* Re: Help with emacs scripting [not found] <F326B9A37B353A449FC7A09B36835F82F4EDAA@MACE.sppdg.ad> @ 2012-04-12 16:10 ` Daniel Sousa 2012-04-12 16:36 ` Andreas Röhler 2012-04-13 13:56 ` Doug Lewan 0 siblings, 2 replies; 8+ messages in thread From: Daniel Sousa @ 2012-04-12 16:10 UTC (permalink / raw) To: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 1783 bytes --] 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();. [-- Attachment #2: Type: text/html, Size: 4508 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Help with emacs scripting 2012-04-12 16:10 ` Help with emacs scripting Daniel Sousa @ 2012-04-12 16:36 ` Andreas Röhler 2012-04-13 13:56 ` Doug Lewan 1 sibling, 0 replies; 8+ messages in thread From: Andreas Röhler @ 2012-04-12 16:36 UTC (permalink / raw) To: help-gnu-emacs Am 12.04.2012 18:10, schrieb Daniel Sousa: > 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();. > looks like a task for that: from a dired-buffer M-x dired-mark-files-regexp RET ... with marked files than M-x dired-do-query-replace-regexp RET ... ^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: Help with emacs scripting 2012-04-12 16:10 ` Help with emacs scripting Daniel Sousa 2012-04-12 16:36 ` Andreas Röhler @ 2012-04-13 13:56 ` Doug Lewan 2012-04-16 0:10 ` Daniel Sousa 1 sibling, 1 reply; 8+ messages in thread From: Doug Lewan @ 2012-04-13 13:56 UTC (permalink / raw) To: help-gnu-emacs@gnu.org; +Cc: Daniel Sousa 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* ()) (defun ds-create-lang-entries () "Change the selection in the current buffer and create a PHP definition in the PHP file. The change to make is \'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\");\'." (interactive) (ensure-php-buffer) (let* ((xsl-format "<xsl:value-of select=\"/xml/lang/%s\" />") (php-format "DEFINE(\"_LANG_%s\", \"bar\");\n") (the-string (buffer-substring-no-properties (point) (mark))) (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. (save-excursion (set-buffer *ds-php-buffer*) (goto-char (point-max)) (insert (format php-format the-STRING))))) (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();. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Help with emacs scripting 2012-04-13 13:56 ` Doug Lewan @ 2012-04-16 0:10 ` Daniel Sousa 0 siblings, 0 replies; 8+ messages in thread From: Daniel Sousa @ 2012-04-16 0:10 UTC (permalink / raw) To: Doug Lewan; +Cc: help-gnu-emacs@gnu.org [-- Attachment #1: Type: text/plain, Size: 6734 bytes --] 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. Since I don't know regular expressions and it's the first time I'm using lisp, I guess this is a terrible code, but it works Once again, thank you for your help. I left here the final code I'll be using: (defvar *ds-languages-dir* "languages") (defvar *ds-php-file* (format "%s/pt.php" *ds-languages-dir*)) (defvar *ds-php-buffer* ()) (defun ds-create-lang-entries () "Change the selection in the current buffer and create a PHP definition in the PHP file. The change to make is \'\' --> \'<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\", \"%s\");\'." (interactive) (ensure-php-buffer) (let ((xsl-format "<xsl:value-of select=\"/xml/lang/_%s\" />") (php-format "DEFINE(\"_LANG_%s\", \"%s\");\n") (oldbuf (current-buffer)) (the-string (buffer-substring-no-properties (point) (mark)))) (save-current-buffer (set-buffer *ds-php-buffer*) (if (search-backward the-string nil t) (progn (let ((endpoint (- (point) 4))) (search-backward "DEFINE" nil t) (let ((the-constant (buffer-substring-no-properties (search-forward "_LANG_") endpoint))) ;; Change the selected text to the appropriate XSL (set-buffer oldbuf) (delete-region (point) (mark)) (goto-char (mark)) (insert (format xsl-format the-constant))))) (progn (set-buffer oldbuf) (let* ((the-constant (replace-regexp-in-string " " "_" (upcase (read-from-minibuffer "constant: "))))) ;; Change the selected text to the appropriate XSL (delete-region (point) (mark)) (goto-char (mark)) (insert (format xsl-format the-constant)) ;; <xsl:value-of select="/xml/lang/_BIG_TEXT" /> (save-excursion (set-buffer *ds-php-buffer*) (goto-char (point-max)) (insert (format php-format the-constant the-string))))))))) (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) On Fri, Apr 13, 2012 at 2:56 PM, Doug Lewan <dougl@shubertticketing.com>wrote: > 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* ()) > > (defun ds-create-lang-entries () > "Change the selection in the current buffer and create a PHP definition > in the PHP file. > The change to make is > \'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\");\'." > (interactive) > (ensure-php-buffer) > (let* ((xsl-format "<xsl:value-of select=\"/xml/lang/%s\" />") > (php-format "DEFINE(\"_LANG_%s\", \"bar\");\n") > (the-string (buffer-substring-no-properties (point) (mark))) > (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. > (save-excursion > (set-buffer *ds-php-buffer*) > (goto-char (point-max)) > (insert (format php-format the-STRING))))) > > (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();. > [-- Attachment #2: Type: text/html, Size: 9697 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Help with emacs scripting @ 2012-04-09 9:37 Daniel Sousa 2012-04-10 16:06 ` Doug Lewan 2012-04-11 11:31 ` Le Wang 0 siblings, 2 replies; 8+ messages in thread From: Daniel Sousa @ 2012-04-09 9:37 UTC (permalink / raw) To: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 556 bytes --] I'm new to emacs and I have not used it much, but I think that it could really help me on the task I'm currently doing. I need to change a web app to make it translatable. Now I have to change a bunch of .xsl files. What I need to do is find the strings, then replace them by something like <xsl:value-of select="/xml/lang/foo" /> and add to a .php something like DEFINE("_LANG_FOO","bar"); I think it would be really easy to create an emacs script to automatically do this, but I don't know how to do it. Can anyone help me? Best regards, Daniel Sousa [-- Attachment #2: Type: text/html, Size: 693 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: Help with emacs scripting 2012-04-09 9:37 Daniel Sousa @ 2012-04-10 16:06 ` Doug Lewan 2012-04-11 0:22 ` Daniel Sousa 2012-04-11 11:31 ` Le Wang 1 sibling, 1 reply; 8+ messages in thread From: Doug Lewan @ 2012-04-10 16:06 UTC (permalink / raw) To: Daniel Sousa, help-gnu-emacs@gnu.org Daniel, This is probably not hard, but more information would be useful. . Are the .xsl and .php files similarly named? "bob.xsl" and "bob.php"? . Do you already have a regular expression to find the strings? Maybe you have a "good" sample of strings to look for. . Does the location of the DEFINE() in the PHP file matter? Could it be replacing something else? (Or interfering with something else?) ,Doug From: Daniel Sousa Sent: Monday, 2012 April 09 05:38 To: help-gnu-emacs@gnu.org Subject: Help with emacs scripting I'm new to emacs and I have not used it much, but I think that it could really help me on the task I'm currently doing. I need to change a web app to make it translatable. Now I have to change a bunch of .xsl files. What I need to do is find the strings, then replace them by something like <xsl:value-of select="/xml/lang/foo" /> and add to a .php something like DEFINE("_LANG_FOO","bar"); I think it would be really easy to create an emacs script to automatically do this, but I don't know how to do it. Can anyone help me? Best regards, Daniel Sousa ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Help with emacs scripting 2012-04-10 16:06 ` Doug Lewan @ 2012-04-11 0:22 ` Daniel Sousa 0 siblings, 0 replies; 8+ messages in thread From: Daniel Sousa @ 2012-04-11 0:22 UTC (permalink / raw) To: Doug Lewan; +Cc: help-gnu-emacs@gnu.org [-- Attachment #1: Type: text/plain, Size: 1565 bytes --] On Tue, Apr 10, 2012 at 5:06 PM, Doug Lewan <dougl@shubertticketing.com>wrote: > Daniel, > > This is probably not hard, but more information would be useful. > > . Are the .xsl and .php files similarly named? "bob.xsl" and "bob.php"? > I have a few .xsl files and all the define()'s go to the same .php file. . Do you already have a regular expression to find the strings? Maybe you > have a "good" sample of strings to look for. > Unfortunately I will have to look for the string manually > . Does the location of the DEFINE() in the PHP file matter? Could it be > replacing something else? (Or interfering with something else?) > We are creating a .php file that is basically only a lot of those defines, then we send it to the translators and we have one of those files for each language. > > ,Doug > Thank you very much for your attention. > > > > From: Daniel Sousa > Sent: Monday, 2012 April 09 05:38 > To: help-gnu-emacs@gnu.org > Subject: Help with emacs scripting > > I'm new to emacs and I have not used it much, but I think that it could > really help me on the task I'm currently doing. > > I need to change a web app to make it translatable. Now I have to change a > bunch of .xsl files. What I need to do is find the strings, then replace > them by something like <xsl:value-of select="/xml/lang/foo" /> and add to a > .php something like DEFINE("_LANG_FOO","bar"); > > I think it would be really easy to create an emacs script to automatically > do this, but I don't know how to do it. Can anyone help me? > > Best regards, > Daniel Sousa > [-- Attachment #2: Type: text/html, Size: 2620 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Help with emacs scripting 2012-04-09 9:37 Daniel Sousa 2012-04-10 16:06 ` Doug Lewan @ 2012-04-11 11:31 ` Le Wang 1 sibling, 0 replies; 8+ messages in thread From: Le Wang @ 2012-04-11 11:31 UTC (permalink / raw) To: Daniel Sousa; +Cc: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 998 bytes --] On Mon, Apr 9, 2012 at 5:37 PM, Daniel Sousa <daniel@sousa.me> wrote: > I'm new to emacs and I have not used it much, but I think that it could > really help me on the task I'm currently doing. > > I need to change a web app to make it translatable. Now I have to change a > bunch of .xsl files. What I need to do is find the strings, then replace > them by something like <xsl:value-of select="/xml/lang/foo" /> and add to a > .php something like DEFINE("_LANG_FOO","bar"); > > I think it would be really easy to create an emacs script to automatically > do this, but I don't know how to do it. Can anyone help me? > Your question is vague. What does the buffer look like? Where does "foo" come from? Is it derived from the string you're searching for? Where does "bar" come from? It's best to start coding this and come back with specific questions when you get stuck. "Do my homework" type of questions aren't likely to get you a full solution. Best regards, > Daniel Sousa > -- Le [-- Attachment #2: Type: text/html, Size: 1575 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-04-16 0:10 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <F326B9A37B353A449FC7A09B36835F82F4EDAA@MACE.sppdg.ad> 2012-04-12 16:10 ` Help with emacs scripting Daniel Sousa 2012-04-12 16:36 ` Andreas Röhler 2012-04-13 13:56 ` Doug Lewan 2012-04-16 0:10 ` Daniel Sousa 2012-04-09 9:37 Daniel Sousa 2012-04-10 16:06 ` Doug Lewan 2012-04-11 0:22 ` Daniel Sousa 2012-04-11 11:31 ` Le Wang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).