Should I use gettext for this instead?
My product must be independent of the brand/logo and it should send a localized message. I don't need more than 2 localizations now (English and Portuguese) but I might need more later so it should be easy to add a translation if my app gets used by an e.g. russian site it should be able to send welcome emails in russian and with the name of the site / brand that uses my app so I supposse what I want to do is something like a whitelabel product. Should I use gettext for this instead?
--
message.body = 'Dear '+ad.name+'\nThank you for registering w开发者_JS百科ith '+self.current_logo+'! To edit your ad,click edit from the menu.'+ self.current_logo+'/vi/'+ad.key().id() +'\nWe invite you to visit our home page where you can find latest information on new business announcements from us. From there you also can upload videos, music and images. \n1) Contact Preferences - Please Select Your Contact Preferences\nInformation Contact\nIf you like, you can also add us on Facebook: apps.facebook.com/koolbusiness'
-- Result for example when we added a domain and then have a brand/logo to use:
---------- Forwarded message ---------- From: Date: Sun, Oct 16, 2011 at 7:29 PM Subject: Honda zoomer To: fridge@koolbusiness.com
Dear Niklas R Thank you for registering with www.koolbusiness.com! To edit your ad,click edit from the menu.www.koolbusiness.com/vi/4361186 We invite you to visit our home page where you can find latest information on new business announcements from us. From there you also can upload videos, music and images. 1) Contact Preferences - Please Select Your Contact Preferences Information Contact If you like, you can also add us on Facebook: apps.facebook.com/koolbusiness
What do you think?
Here's how the message builds up. The exact contents are not important but important is that it works in many languages. You can do it with gettext but I think this case is so simple that I can do it in the source since English and Portuguese are going to be the main languages of the app for some time, then maybe we add spanish, french, swedish but it's a non-technical job writing these translations.
Update
Since gettext appears to be the choice I wonder about the implementation. 2 things in particular were whether to include HTML and how to display a special character like the ampersand. I'm currenly using this that renders the correct output but is the code right?
django.po
msgid "Accessories & Parts"
msgstr "Partes & Acessórios"
msgid "Entire Brasil"
msgstr "«Todo Brasil»"
msgid "You can post ads for free. You can search for classified advertisements from professionals as well as private individuals; such as: cars, property, employment, pieces of furniture, electronics and others."
msgstr "<a href='/ai'>Anúncios</a> no site Montao.com.br são colocados manualmente pelo usuário aqui. <br/><a href='/li'>Todos</a> os anúncios são revistos pela equipe do Montao.com.br. O anúncio será visível durante dois messes. Grátis!"
For the new email translation I could use gettext but I must get both the variables and the translation right and that could be tricky but anyway I'm trying to start sketch it so that it can be localized to many languages:
msgid "Dear %s\nThank you for registering with %s! To edit your ad,click edit from the menu.%s/vi/%s \nWe invite you to visit our home page where you can find latest information on new business announcements from us. From there you also can upload videos, music and images. \n1) Contact Preferences - Please Select Your Contact Preferences\nInformation Contact\nIf you like, you can also add us on Facebook: apps.facebook.com/koolbusiness"
msgstr ""
However my experience says that it's much better to make 2 cron jobs, one for each translation, than one cron job for many translations since a request could accidentally get the wrong cookie due to cookie cooruption or likewise. So this translation task is also for completeness and consistency even though the first attempt works for English and is easily exandable to 2 languages a complete localization with gettext is something I think is good to have.
Surely gettext is the best solution if you want localization (just remember to use placeholders instead of concatenating strings like you did in your example).
Regarding white-labeling, if ALL the customer-dependent content is also localizable, then gettext will do just fine - you hit two birds with one stone, plus gettext is somewhat standard so all localization tools and professionals will work without issues. I guess however that there are things that are not really localizable (like pictures), so I suggest you to keep some kind of pre-defined structure for such content, so each customer can insert his content without having to touch the code (e.g. the logo is always named Logo.png, with fixed size).
It is common practice to keep the msgid in .po files equal to the text in the source language and this works well for short simple sentences. In case you have long sentences, with special characters and HTML or other tags, I would suggest using an ID, like "result_message", and then manually populating a master resource file (e.g. for English). This makes the file a bit less self-describing and takes a little more effort, but in the long run it's the best solution if you want to stay sane (and keep resource files as small as possible).
To keep the files in sync between master and translated, there are then a number of tools, as I wrote here: Keeping i18n resources synced
精彩评论