Any text that is displayed to the user will need to be pulled out into project/locale specific dicts. These dicts will be located under amgut.lib.locale_data, and each portal will have its own. For instance, the American Gut portal text and media will fall under amgut.lib.locale_data.american_gut. The motivation for portal specific, instead of language specific localization is that many countries rely on en_UK, but we need to play for having different branding (e.g., Australian Gut) moving forward.
Each locale_data module needs to provide two dicts, text_locale and media_locale. The structure of text_locale is as follows:
text_locale = {
'name_of_template.html': {
'INFORMATIVE_VARIABLE_NAME': 'The text that is displayed'
}
}
media_locale = {'INFORMATIVE_VARIABLE_NAME': '/path/to/media.jpg'}
text_locale is per-template which minimizes what needs to be passed into render from the handlers. media_locale is not per-template as much of the media is common across templates, such as the logo.
In the __init__ for amgut.lib.locale_data, there is a media_locale that represents anything common regardless of portal. This dict is updated by the project specific media_locale.
For localization data, all handlers will need to add:
from amgut import text_locale, media_locale
The package-level __init__ will resolve the appropriate locale data. All handlers wishing to use the locale data will need to specify the locale over render. For instance:
class MyHandler(BaseHandler):
def get(self):
# stuff of interest
template = 'really_awesome.html'
self.render(template, ...whatever..., text_locale=text_locale[template], media_locale=media_locale)
Within the templates, all user visible text will need to be replaced with:
<!-- former -->
<p><strong>very</strong> informative message</p>
<!-- new style -->
<p>{% raw text_locale['INFORMATIVE_MESSAGE'] %}</p>
All variables should be expressed with raw, which will let us preserve html formatting and tags within the locale dicts.
And finally, the list of templates to knock off. A template is considered completed once the text has been pulled out and replaced with locale lookups, the relevant locale entries updated, and the handler has been updated.
Any text that is displayed to the user will need to be pulled out into project/locale specific dicts. These dicts will be located under
amgut.lib.locale_data
, and each portal will have its own. For instance, the American Gut portal text and media will fall underamgut.lib.locale_data.american_gut
. The motivation for portal specific, instead of language specific localization is that many countries rely on en_UK, but we need to play for having different branding (e.g., Australian Gut) moving forward.Each
locale_data
module needs to provide two dicts,text_locale
andmedia_locale
. The structure oftext_locale
is as follows:text_locale
is per-template which minimizes what needs to be passed intorender
from the handlers.media_locale
is not per-template as much of the media is common across templates, such as the logo.In the
__init__
foramgut.lib.locale_data
, there is amedia_locale
that represents anything common regardless of portal. Thisdict
is updated by the project specificmedia_locale
.For localization data, all handlers will need to add:
The package-level
__init__
will resolve the appropriate locale data. All handlers wishing to use the locale data will need to specify the locale over render. For instance:Within the templates, all user visible text will need to be replaced with:
All variables should be expressed with
raw
, which will let us preserve html formatting and tags within the locale dicts.And finally, the list of templates to knock off. A template is considered completed once the text has been pulled out and replaced with locale lookups, the relevant locale entries updated, and the handler has been updated.