-
-
Notifications
You must be signed in to change notification settings - Fork 32
i18n
i18n works with an home made module inspired by awesome Rubenv's angular-gettext : https://github.com/rubenv/angular-gettext
Text in source code must be in english. It will be the unique key that identifies translated texts. A separated process will crawl all the source code, extracts those texts, and will send them to our translation tool: transifex.
Once a day, a process will pull new translated text and create a pull request.
This system works pretty well for short and unformatted text. For longer texts, you may use an article (please contact [email protected] for this use case).
Simply use v-translate directive :
<span v-translate>
Hello world!
</span>
Note that node content can only be simple text. this won't work as expected :
<span v-translate>
Hello <b>world</b>!
</span>
If you need to specify a translation context to translators, use translate-context attribute :
<span v-translate translate-context="Message to users">
Hello world!
</span>
... And also in template bindings, use $gettext
method :
<template>
<img :title="$gettext('Hello World')" :alt="altText">
</template>
<script>
export defaults {
computed: {
altText() {
return this.$gettext('Alternative hello');
}
}
}
</script>
$gettext
accepts a second argument : translation context :
const message = this.$gettext('Hello world!', 'Message to users')
As $gettext
in binded to Vue model, you can't use it in a separated js file.
... is not possible.
API messages are not explicitly present in c2c_ui source code. For this use case, add an hard-coded javascript comment :
<template>
<!-- $gettext('an API message') -->
<span></span>
</template>
<script>
export defaults {
computed: {
altText() {
// could be :
// $gettext('message A')
// $gettext('message B')
return api.getMessage();
}
}
}
</script>
... can be found in the discussion in this issue.
We have migrated our CI to Github Actions and have automated the i18n workflow:
- Every time a commit is made on the
master
branch, the i18n keys are extracted from code and uploaded to Transifex. - Once a day, a script checks whether changes were introduced in Transifex, and, if applies, creates or updates PR to merge changes into
master
branch. - Users can then review changes and merge the PR as appropriate. Or even edit it if needed.
- 🏠 Home
- 📋 Changelog
- 🛠️ Dev environment
- 🎉 Resolving issues
- 🤖 CI/CD
- 📝 Tech docs
- 🎓 Courses
- 🤓 Admin