There are several ways to accomplish that, but it would be easy for your translation-team to have all texts in the same PO file, and easy for you to have it all in the same MO file 🙂
Let’s start where everything starts in Django; the URLs:
In other words: “/js/locale.js” will be rendered by this view: “myproject.views.js_locale”. Let’s create that view:
Let’s have a look at the template:
So we’re looping over the list where each item (also) is a list with three indexes:
Accessing the URL “/js/locale.js” will now provide you this:
Let’s include that file in our document template (or where ever you need it):
From now on you can access those translated texts from any script.
For example “assets/js/scripts.js” could now display a confirm in Spanish, when translated:
Everything works! But…
As your texts will grow while proceeding your client-side scripts, it will pollute your view with a lot of strings, who don’t really belong there. So let’s move those to a separate file. My approach is to put all the ‘common’ texts in there, and let the text-namespace be defined in the view (or perhaps several views).
Sometimes, when using Joomla, you’re in a situation where you want to display one or more modules in your article.
Either as a plugin substitute (module might not be available as plugin) or as a real module-position (where more modules can appear in a module-position on one or more menu-items).
The trick is using the “loadposition” plugin.
You might have noticed when adding a module the normal way, that in stead of clicking the Select Position button, you might as well just enter the name of the module-position directly into the text-field. This doesn’t has to be a name of a module-position available in your templates, just create a new name which makes sense for its purpose. For now I’ll just call it “xyz”.
Like for all ‘regular’ modules, tell Joomla under which menu-items this may be displayed.
In your article(s) you can pull in all modules attached to module-position “xyz”, by inserting the plugin-code “loadposition” with “xyz” as an argument:
When the article is a part of the allowed menu-item(s) of a module, that module will appear in this article.
I won’t have to pencil out that when working with dates, that timezone-awareness is crucial.
Here are two pages you might want to look at if that is new for you:
Though I’ve had some headaches the last 24 hrs getting it working with timestamps.
In my (Socify.it) project I’m using timestamps to recieve a (Unix) timestamp through a webservice and have to find a specific file on a FTP server matching that timestamp, with in another format (like “cam1-%Y-%m-%d-%H-%M-%S.jpg“).
Your timestamps must be ‘neutral’. Afterwards you can extract a time-zone dependent date-time.
datetime.utcfromtimestamp(timestamp) will set a date determined by what you have in you Django settings’s TIME_ZONE.
You’ll need to ‘normalize it’ with the timezone that has saved that date-time.
Now let’s do that the other way around. In this example I’ll try to keep the timestamp ‘neutral’, in order to be able to extract a time-zone dependent date-time, later on :
Calendar.timegm() is our friend here, where
Let’s import that and try:
Check yourself by converting it back. Also try
time.mktime() in stead of
calendar.timegm() and see the unwanted difference!
But after a while it was time to work locally with my favourite weapon of choice, Django.
Django seemed to be wiped away too, including PIP.
Below is how I tested and retrieved it, it might come handy when you’re in the same situation. See if it’s usefull for you: