Open fedelibre opened 9 years ago
locale
is not meant to be a list. When you want to use internalization, you'll typically have multiple configuration files:
Let's assume your main config file is called config.json
, and your locale config files are en.json
and fr.json
.
You would have:
en.json
with {"locale": "en"}
fr.json
with {"locale": "fr"}
config.json
with all the restThen, when you want to build the translations for French, you'd run cactus -c config.json -c fr.json messages:make
.
This also allows you to deploy to different endpoints depending on the locale, etc.
Does this help?
Note that in your case you should probably also have a it.json
.
Thanks, now I have a better understanding of how config works. However, I can't make the translation work. I don't understand where {% trans %} should be placed exactly.
A minimal working example would be extremely helpful. I set up a basic project example.
When I run cactus messages:make -c config.json -c it.json
(the subcommand must be before the options, otherwise I get an error), the directory locale/it/LC_MESSAGES
is created but no file inside of it.
When I run cactus serve
I get an error:
django.template.base.TemplateSyntaxError: Invalid block tag: 'trans', expected 'endblock'
I tried changing the string from:
{% trans %} <p>This is the string to be translated</p> {% endtrans %}
to:
{% block trans %} <p>This is the string to be translated</p> {% endblock %}
Now cactus serve
works but again no file generated under locale/.
I do think that there is less documentation about the translation.
@fedelibre you should use {% trans string %}
. You can find more details from django documentation
@krallin I have successfully create .po file in locale folder with the command line. And also defined a msgid "title" in .po file and use in {% trans title %}
. But it only return a empty string. I don't know what I have done wrong here. Any suggestion?
{% language 'en' %}
{% block head %}
<title>{% trans title %}</title>
{% endblock head %}
{% endlanguage %}
Furthermore, I print the current language with below codes, it shows "en-us" instead of "en"
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
Ok guys, this issue helped me out a lot. There is one thing that I had to do to get translation working. At the top of all my templates right below the extends tag I had to type
{% load i18n %}
This took care of the "invalid block tag error". Hope this helps. Cactus just generates a static site, so if you say cactus build -c es.json it will build the complete site using the LC_MESSAGES content in spanish, then you can deploy and proceed to build other languages.
@jangeador Cheers! It really gets the thing done. Thanks.
@krallin Ever considered to include the docs in the repository in a way that can be easily updated and accessed via, for example, Read the Docs? It seems to me that the tool is evolving faster than the documentation and that it would make more sense if the docs are separated from the Cactus for Mac website... we could even include some examples of plugins there.
When i run: cactus messages:make -c config.json -c en.json or cactus messages:make -c config.json -c it.json
it generates file directories e, n and i, t ---- somebody had a similar experience?
I had the same issue last time I tried to use this. It used to work just fine, then it started doing this. Never figured out the problem but I had a hunch that it was because of python 3 and the way it handles strings.
@jangeador i am running py2.7 & Django1.6.11
I know, I tried to run both Python 2 and 3 when I was troubleshooting and I could not get it to run correctly on either. I was not referring to the python version that you are running, it is something that changed in the cactus package or the i18n package between August 2015 and now that broke this feature. I did not try to use earlier versions of Cactus now that I think about it.
Hello guys!
Did anyone make i18n working properly? I didn't yet.
I have my "pt.json" file with this code inside: https://gist.github.com/otondin/7ba55c170a0aad68e07924440f70a8ae
And when I ran the command cactus messages: make -c config.json -c en.json
I get this output right on the terminal: https://gist.github.com/otondin/20cc32016e4ce1aec07073ce46bd4286
I would appreciate any help! Thank you!
The 'e', 'n', 'i' ,'t' subdirectories are apparently due to a bug in Django 1.6.11, which is used by Cactus. I have not investigated this in depth, the bug might be in Cactus, too, but changing one line of code in Django did it for me. Unfortunately, cactus does not work with later Django versions.
Forget what I just wrote... the bug is in Cactus. Leave your Django installation alone. There is an easy workaround, though. In your project directory, just run
django-admin.py makemessages -l en
where 'en' is of course the locale you want to build a PO file for.
I created a pull request to fix this: https://github.com/eudicots/Cactus/pull/267
The concise information in
skeleton/locale/README.md
is not helping me much. Can you provide a working example? I have a couple of questions:how many languages can I set in config.json? One is working, but if I try to set an array with two values I get an error when I run
cactus messages:make
(TypeError: unhashable type: 'list'):The config file is meant to be one per website? I should use one config file for each different language?
How should the block look like? I tried this but no po file is generated: