This problem has been bothering me for a while, but I would like to fix it once and for all.
I am using the twig template engine in my PHP application. I am using the latest version of Poedit (which uses xgettext 0.18.1) to parse my files for translation strings.
I have set up Poedit to work with twig using these instructions.
Everything works well, but the problem is that when I update my Poedit catalogue, I get errors like this:
1:24:45 PM: somefile.twig:5: warning: unterminated string
1:24:45 PM: somefile.twig:10: warning: unterminated string
This is the dialog:
And this is the file in question:
{% extends somevar ? 'one.twig' : 'two.twig' %}
{% block blah %}
Blah blah
{% endblock %}
{% block blah2%}
<div id="some-id" class="some-class">
some content
</div>
{% endblock %}
However, if I click OK in the error dialog, everything seems to be fine and the strings from the twig template are then loaded into the catalogue.
I know there is a gettext-extractor for twig that has been released recently to pick out the translation strings. However, there are some possible issues:
I am not using the symfony 2 framework and am not using the intl extension for twig (we have built our own to suit our purposes).
We use a different character for our gettext strings {{ t('some string') }}
We would prefer not to have to introduce more external dependencies unless we really have too, otherwise someone trying to get the strings would need to set up twig and the gettext extractor.
Is there a flag I can pass to xgettext to solve this problem? The parsing works fine. I just prefer that the error to not be thrown by gettext.
Change Setting like this:
Go to Prefernces -> Parsers
Select PHP -> Edit
List of Extentions .... -> .php,.phtml
Insert this "xgettext --language=PHP --force-po -o %o %C %K %F" into Parser Command: field.
And also Catalog --> Properties --> Translation Properties TAB --> Charset utf-8
So I continued using that workflow for a few days and found the following problem:
If I have a resource bundle key like so: Test, the settings I was using previously would not pick up the key.
Since I already had a small PHP script in the background to monitor and compile my assets using Assetic, I simply added a few more lines for the twig templates to be compiled into PHP files (http://twig.sensiolabs.org/doc/extensions/i18n.html#extracting-template-strings).
I then remove the Twig parser from POEdit and now, all the template strings are just parsed from PHP files, which works great!
While this solution works, I would still like to find a way to get POEdit and gettext to parse twig files natively. However, if anyone is looking for a solution, this one should work quite well in the meantime.
Related
I have just started learning the Forth programming language.
I'm using Gforth on Ubuntu. In Gforth interactive console, I want to do indentation but it requires changing line. Enter key didn't work, it executed code. For comparison, for example, when one tests JavaScript code in web browser console, shift+enter change line without executing code. I want something like that. What key should I press? Is there a way other than using text editors like vim?
Best.
Gforth doesn't support multiline editing (see the manual).
A workaround is to edit a file in your favorite editor in another window and reload this file in Gforth console as:
include /tmp/scratch.fs
An external file can be also edited in Gforth console via a command like:
"vim /tmp/scratch.fs" system
So a one-liner for that is:
"vim /tmp/scratch.fs" system "/tmp/scratch.fs" included
That can be wrapped into a definition as:
: scratch "vim /tmp/scratch.fs" system "/tmp/scratch.fs" included ;
So the word scratch will open an editor and than load the edited file.
NB: if you use a quite old build of Gforth, you have to use s" ccc" instead of "ccc" for string literals.
To conditionally include/exclude some parts in a file the words [defined] and [if] can be used; to erase the previous instance of the loaded definitions the word marker can be used as:
[defined] _clear [if] _clear [then]
marker _clear
\ some definitions
\ ...
Take into account that usual control-flow words can be used in definitions only.
I'm trying to convert latex code embedded in an HTML document (Intended to be used with a Javascript shim) into MathML. Pandoc seems like a great tool. Following this example: http://pandoc.org/demos.html,
pandoc input.html -s --latexmathml -o output.html
Produces no change in the file. I even made a barebones blank HTML file with various text expressions to test; no change in the output. What am I missing?
http://math.etsu.edu/LaTeXMathML/ This site, linked to by Pandoc, appears to show documentation for a standalone case, but it uses a JS shim instead of outputting the MathML directly. (I think it has the browser render dynamically-rendered MathML, but doesn't actually output it to the file) It's also missing some basic functionality, like own-line functions with \begin{equation}.
I've spent several hours googling ways to accomplish this. Any ideas? The only fully-working solution I've found is https://www.mathtowebonline.com/ This website. There's also a python module called latex2mathml, but it's also missing large chunks of the spec.
You'll need the --mathml flag (not the --latexmathml flag) to generate MathML and the tex_math_dollars extension enabled for reading the math between dollar signs:
$ echo '<p>$$x = 4$$</p>' | pandoc -f html+tex_math_dollars -t html --mathml
<p>
<math display="block" xmlns="http://www.w3.org/1998/Math/MathML">
<semantics>
<mrow><mi>x</mi><mo>=</mo><mn>4</mn></mrow><annotation encoding="application/x-tex">x = 4</annotation>
</semantics>
</math>
</p>
Or maybe you're better off using somehting like snuggleTeX or LaTeXMathML.js...
As recommended by Symfony I'm using xlf files for the translations.
I want to store a message which has a HTML tags, let's say:
Welcome back <a href='/user/profile'>user</a>.
I have discovered that you can't include this literal in the target section because you get an exception caused by the "<" and ">" chars.
I'm unable to find a way to escape this chars unless using the < and > .
Is there another solution?. Any suggestions?
Using ZfcTwig for ZF2 and twig-gettext-extractor, I still cannot extract messages for translation from twig-files by poedit. I works if I used the formal twig keyword for translation {% trans(MY_TEXT) %} but not for the in-built view helper translate. {{ translate(MY_Text) }} does the translation but poedit is just ignoring it. For new twig files, I want as usual let poedit do the job....
Any ideas for a solution?
Maybe you need to edit catalog properties keywords to be visible for translations. Open PoEdit, go to Catalog -> Properties -> Sources keywords and add another keyword "translate". Here I attach an screenshot.
The problem is that the extractor you are using is just caching the files and running them through xgettext to extract calls to trans/translate/_/.. (keywords as suggested by Conti. Alas ZfcTwig will crosscompile calls to ZF2 plugins into plugin('translate')->__invoke('Your Text to be translated'). You could of course now add __invoke as a new keyword in poedit or whatever you favorite gui for using xgettext is, but it will now find all calls to all view helpers not just those to translate.
I ran into this problem myself and I have not come up with a satisfying solution. The Twig Gettext Extension looks promising in terms of writing your own customized POT-File generator that will handle translate and translatePlural view helper calls. Using the extension as is will bypass all translation from ZF2. ZF2 parses .mo files into an internal structure rather than using the php-gettext mod.
All in all I gave up on automated po(t) file generation for ZF2+ZfcTwig for now and am back to phpArray.
Am going around the houses trying to find a way to implement a simple filter.
I want to create the equivalent of some Smarty "tags" to make porting easier, notably
{mail_to} http://www.smarty.net/manual/en/language.function.mailto.php
I seem to be going around in circles between the jinga2 docs
http://jinja.pocoo.org/2/documentation/extensions#module-jinja2.ext
and the webhelpers
http://pylonshq.com/docs/en/0.9.7/modules/templating/
What I'm expecting to write is something like
{% mail_to user=c.user.email encode='hex' %}
Cant figure out how to piece it all together, ie location of lib and how to load for usage.
tia
Write you extension and put it into lib/extensions.py
To load you extension into environment do in config/environment.py:
from MYAPP.lib import extensions
config['pylons.app_globals'].jinja2_env = Environment(loader=ChoiceLoader(
[FileSystemLoader(path) for path in paths['templates']]),
extensions=[extensions.YOU_EXTENSION_MAIL_TO_CLASS]))
# If you extension use some options, you can init it
config['pylons.app_globals'].jinja2_env.mail_to_smtp_host = 'some_host'
After in yours templates simply call {% mail_to arg1, arg2 %}