JavaScript translated strings in EF
@garryyao
// study page entrance
Widget.extend({
'sig/start': function () {
// load translation string
this.query('blurb!656312').spread(function(blurb) {
this.html(template({
'help-link': blurb.translation
}));
});
}
});
The very primitive form, where a ajax query is to fetch the translated blurb
a dedicated "admin" system to manage the translation of blurbs
A more declarative way of using blurbs, we create a "blurb widget" in TroopJS to express it in a HTML template
<a class="footer-help" aria-label="Need Help?"
data-weave="troopjs-ef/blurb/widget"
data-blurb-id="644325"
href="{{./help-link}}" target="_blank">
</a>
Not very natural and easy to write until we invent the React way of expressing it
<Blurb id="652174">
Welcome to EF, <strong>{username}</strong>!
</Blurb>
<Blurb id="652174">
Welcome to EF, <strong>{username}</strong>!
</Blurb>
<title data-translate>Free English Test Online</title>
<meta name="description" content="{{'Take our quick English test!'|translate}}">
<meta name="author" content="{{'EF - Education First'|translate}}">
...
<a class="btn btn-primary"
href="/content{{'/en'|translate}}/about.html"
data-translate>LEARN MORE</a>
Make the translations as different "versions", statically generate many language versions from a source template
| Path | Description |
|--------------------|----------------------------|
| /content/ | Contains generated html files |
| /l10n_po | Language po files |
| /l10n_tpl | Contains the html templates |
client directory structure
| Path | Description |
|--------------------|----------------------------|
| /content/ | Contains generated html files |
| /l10n_po | Language po files |
| /l10n_tpl | Contains the html templates |
application directory structure
#: l10n_tpl/content/en.html:51
#: l10n_tpl/content/en.html:65
#: l10n_tpl/content/en.html:7
msgid "Free English Test Online"
msgstr ""
#. Call-to-action
#: l10n_tpl/content/en.html:128
msgid "LEARN MORE ABOUT US"
msgstr ""
we created the build process to extract the translations into a gettext POT file
#: l10n_tpl/content/en.html:51
#: l10n_tpl/content/en.html:65
#: l10n_tpl/content/en.html:7
msgid "Free English Test Online"
msgstr "免费在线英语测试"
#. Call-to-action
#: l10n_tpl/content/en.html:128
msgid "LEARN MORE ABOUT US"
msgstr "了解更多"
Translation are worked out on relevant PO files (tracked in Git),
through either an local gettext editor or online service like Transifex
<title>免费在线英语测试</title>
<meta name="description" content="来做我们世界级语言专家研发的快捷的英语测试题吧!">
<meta name="author" content="英孚—英孚教育">
...
<a class="btn btn-primary" href="/content/efset/zh/about.html">了解更多</a>
Then again the build process make sure all changes will be merged back to Git, and compile the PO files to "language version" of HTML templates.