Thank you very much, that does almost what I wanted. I made a few changes to make the script work and then I changed it to check if the string was already in the .php files and if it is, it uses it.
A concrete example always makes vague requirements clearer.
Thank you.
I think the following will do what you want.
The process is this:
1. Go through the XSL buffer(s),
2. sweeping the strings of interest and
3. type C-cC-c to process.
4. Move on to the next string and repeat.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar *ds-languages-dir* "languages")
(defvar *ds-php-file* (format "%s/pt.php" *ds-languages-dir*))
(defvar *ds-php-buffer* ())"Change the selection in the current buffer and create a PHP definition in the PHP file.
(defun ds-create-lang-entries ()
The change to make is(interactive)
\'MATCHED_STRING\'
--> \'<xsl:value-of select=\"/xml/lang/MATCHED_STRING\" />\'.
The addition to the PHP file is made at the end of the file;
it is \'DEFINE(\"_LANG_MATCHED_STRING\", \"bar\");\'."
(ensure-php-buffer)
(let* ((xsl-format "<xsl:value-of select=\"/xml/lang/%s\" />")(the-string (buffer-substring-no-properties (point) (mark)))
(php-format "DEFINE(\"_LANG_%s\", \"bar\");\n")
(the-STRING (upcase the-string)))
;; Change the selected text to the appropriate XSL
(delete-region (point) (mark))
(goto-char (mark))
(insert (format xsl-format the-string))
;; Now add a PHP definition at the end of the PHP file.(insert (format php-format the-STRING)))))
(save-excursion
(set-buffer *ds-php-buffer*)
(goto-char (point-max))
(defun ensure-php-buffer ()
"Make sure that everything about the PHP buffer is good."
(unless (file-directory-p *ds-languages-dir*) (make-directory *ds-languages-dir* t))
(unless *ds-php-buffer* (setq *ds-php-buffer* (find-file-noselect *ds-php-file*))))
(local-set-key "\C-c\C-c" 'ds-create-lang-entries)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
I hope this helps.
,Doug
From: help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org [mailto:help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org] On Behalf Of Daniel Sousa
Sent: Thursday, 2012 April 12 12:10
To: help-gnu-emacs@gnu.org
Subject: Re: Help with emacs scripting
I'm majoring in applied math and computation, I know pretty well that computers are dumb xD
I think neither of you have understood what I wanted, so I'll give you an example.
I have a lot of .xsl that generate pages and I want to make those pages translatable. I migth have the file, for exemple, welcome.xsl:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" encoding="iso-8859-1" />
<xsl:template match="/">
<xsl:if test="welcome">
<p>Bem-vindo</p>
</xsl:if>
<ul>
<xsl:for-each select="elements">
<li>Coisa <xsl:value-of select="name" /></li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
And I wanted to make this translatable, so I change this to
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" encoding="iso-8859-1" />
<xsl:template match="/xml">
<xsl:if test="welcome">
<p><xsl:value-of select="/xml/lang/_WELCOME" /></p>
</xsl:if>
<ul>
<xsl:for-each select="elements">
<li> <xsl:value-of select="/xml/lang/_STUFF" /> <xsl:value-of select="name" /></li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
And I create a languages/pt.php with:
define('_LANG_WELCOME','Bem-vindo');
define('_LANG_STUFF','Coisa');
I have a piece of php code that puts in the xml all the constants that begin with "_LANG".
I have a lot of these .xsl and I need to go manually through them all to find the strings that I want to make translatable. What I want this script to do is, on my input put that <xsl:value-of select="/xml/lang/_STUFF" /> thing on the place I select and append to the language file the repective define();.