Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

contributor docs: Reorganize internationalization documentation.

Alya Abbotte0cf9d33b856
diff --git a/docs/translating/internationalization.md b/docs/translating/internationalization.md
index 8e28dc6054c..21f3c12874d 100644
--- a/docs/translating/internationalization.md
+++ b/docs/translating/internationalization.md
@@ -1,137 +1,86 @@
# Internationalization for developers
-Zulip, like many popular applications, is designed with
-internationalization (i18n) in mind, which means users can fully use
-the Zulip UI in their preferred language.
-
-This article aims to teach Zulip contributors enough about
-internationalization and Zulip's tools for it so that they can make
-correct decisions about how to tag strings for translation. A few
-principles are important in how we think about internationalization:
-
-- Our goal is for **all end-user facing strings** in Zulip to be
- tagged for translation in both [HTML templates](#html-templates) and
- code, and our linters attempt to enforce this. There are some
- exceptions: we don't tag strings in Zulip's landing pages
- (e.g., /features/) and other documentation (e.g., /help/) for
- translation at this time (though we do aim for those pages to be
- usable with tools like Google Translate).
-- Translating all the strings in Zulip for a language and maintaining
- that translation is a lot of work, and that work scales with the
- number of strings tagged for translation in Zulip. For this reason,
- we put significant effort into only tagging for translation content
- that will actually be displayed to users, and minimizing unnecessary
- user-facing strings in the product.
-- In order for a translated user experience to be good, every UI
- element needs to be built in a way that supports i18n.
-- This is more about string consistency in general, but we have a
- "Sentence case" [capitalization
- policy](translating.md#capitalization) that we enforce using linters
- that check all strings tagged for translation in Zulip.
-
-This article aims to provide a brief introduction. We recommend the
-[EdX i18n guide][edx-i18n] as a great resource for learning more about
-internationalization in general; we agree with essentially all of
-their style guidelines.
+Zulip is designed with internationalization (i18n) in mind, which lets users
+view the Zulip UI in their preferred language. As a developer, it's your
+responsibility to make sure that:
-[edx-i18n]: https://docs.openedx.org/en/latest/developers/references/developer_guide/internationalization/i18n.html
+- UIs you implement look good when translated into languages other than English.
+- Any strings your code changes touch are correctly marked for translation.
-## Key details about human language
+This pages gives concrete guidance on how to accomplish these goals, as well as
+providing additional context for those who are curious.
-There are a few critical details about human language that are important
-to understand when implementing an internationalized application:
+## How internationalization impacts Zulip's UI
-- **Punctuation** varies between languages (e.g., Japanese doesn't use
- `.`s at the end of sentences). This means that you should always
- include end-of-sentence symbols like `.` and `?` inside the
- to-be-translated strings, so that translators can correctly
- translate the content.
-- **Word order** varies between languages (e.g., some languages put
- subjects before verbs, others the other way around). This means
- that **concatenating translatable strings** produces broken results
- (more details with examples are below).
-- The **width of the string needed to express something** varies
- dramatically between languages; this means you can't just hardcode a
- button or widget to look great for English and expect it to work in
- all languages. German is a good test case, as it has a lot of long
- words, as is Japanese (as character-based languages use a lot less
- width).
-- This is more about how i18n tooling works, but in code, the
- translation function must be passed the string to translate, not a
- variable containing the target string. Otherwise, the parsers that
- extract the strings in a project to send to translators will not
- find your string.
+Always be mindful that **text width is not a constant**. The width of the string
+needed to express something varies dramatically between languages. This means
+you can't just hardcode a button or widget to look great for English and expect
+it to work in all languages.
-There's a lot of other interesting differences that are important for
-i18n (e.g., Zulip has a "full name" field rather than "first name" and
-"last name" because different cultures order the surnames and given
-names differently), but the above issues are likely to be relevant to
-most people working on Zulip.
+You can test your work by changing the lengths of strings to be 50% longer and
+50% shorter than in English. For strings that are already in the Zulip UI,
+Russian is a good test case for translations that are generally longer than
+English. Japanese translations are generally shorter.
-## Translation process
+## What should be marked for translation
-The end-to-end tooling process for translations in Zulip is as follows.
+Our goal is for **all user-facing strings** in Zulip to be tagged for
+translation in both [HTML templates][html-templates] and code, and our linters
+attempt to enforce this. This applies to every bit of language a user might see,
+including things like error strings, dates, and email content.
-1. The strings are marked for translation (see sections for
- [backend](#backend-translations) and
- [frontend](#frontend-translations) translations for details on
- this).
+The exceptions to the "tag everything users sees" rule are:
-2. Translation resource files are created using the
- `./manage.py makemessages` command. This command will create, for
- each language, a resource file called `translations.json` for the
- frontend strings and `django.po` for the backend strings.
+- Landing pages (e.g., <https://zulip.com/features/>)
+- [Help center pages](../documentation/helpcenter.md)
+- [Zulip updates](https://zulip.com/help/configure-automated-notices#zulip-update-announcements)
- The `makemessages` command is idempotent in that:
+We do aim for those pages to be usable with tools like Google Translate.
- - It will only delete singular keys in the resource file when they
- are no longer used in Zulip code.
- - It will only delete plural keys (see below for the documentation
- on plural translations) when the corresponding singular key is
- absent.
- - It will not override the value of a singular key if that value
- contains a translated text.
-
-3. Those resource files are uploaded to Transifex by a maintainer using the
- `./tools/i18n/push-translations` command (which invokes a Transifex
- API tool, `tx push`, internally).
+Note that the "user-facing" part is also important. To make good use of our
+community translators' valuable time, we only tag content that will actually be
+displayed to users.
-4. Translators translate the strings in the Transifex UI. (In theory,
- it's possible to translate locally and then do `tx push`, but
- because our workflow is to sync translation data from Transifex to
- Zulip, making changes to translations in Zulip risks having the
- changes blown away by a data sync, so that's only a viable model
- for a language that has no translations yet).
+## How to mark a string for translation
-5. The translations are downloaded back into the codebase by a
- maintainer, using `tools/i18n/sync-translations` (which invokes the
- Transifex API tool, `tx pull`, internally).
+When tagging strings for translation, variation between languages means that you
+have to be careful in exactly what you tag, and how you split things up:
-If you're interested, you may also want to check out the [translators'
-workflow](translating.md#translators-workflow), just so you have a
-sense of how everything fits together.
+- **Punctuation** varies between languages (e.g., Japanese doesn't use
+ `.`s at the end of sentences). This means that you should always
+ include end-of-sentence symbols like `.` and `?` inside the
+ to-be-translated strings, so that translators can correctly
+ translate the content.
+- **Word order** varies between languages (e.g., some languages put subjects
+ before verbs, others the other way around). This means that **concatenating
+ translatable strings** produces broken results. If a sentence contains a
+ variable, never tag the part before the variable separately from the part
+ after the variable.
+- **Strings with numerals** (e.g., "5 bananas") work quite differently between
+ languages, so double-check your work when tagging strings with numerals for
+ translation.
-## Translation resource files
+Note also that we have a "sentence case" [capitalization
+policy](translating.md#capitalization) that we enforce using linters that check
+all strings tagged for translation in Zulip.
-All the translation magic happens through resource files, which hold
-the translated text. Backend resource files are located at
-`locale/<lang_code>/LC_MESSAGES/django.po`, while frontend
-resource files are located at
-`locale/<lang_code>/translations.json` (and mobile at
-`mobile.json`).
+## Translation syntax in Zulip
-These files are uploaded to [Transifex][], where they can be translated.
+A few general notes:
-## HTML Templates
+- Translation functions must be passed the string to translate, not a
+ variable containing the target string. Otherwise, the parsers that
+ extract the strings in a project to send to translators will not
+ find your string.
-Zulip makes use of the [Jinja2][] templating system for the backend
-and [Handlebars][] for the frontend. Our [HTML templates][html-templates]
-documentation includes useful information on the syntax and
-behavior of these systems.
+- Zulip makes use of the [Jinja2][] templating system for the backend
+ and [Handlebars][] for the frontend. Our [HTML templates][html-templates]
+ documentation includes useful information on the syntax and
+ behavior of these systems.
-## Backend translations
+### Backend translations
-### Jinja2 templates
+#### Jinja2 templates
All user-facing text in the Zulip UI should be generated by an Jinja2 HTML
template so that it can be translated.
@@ -143,24 +92,25 @@ can use the `_()` function in the templates like this:
{{ _("English text") }}
```
-If a piece of text contains both a literal string component and variables,
-you can use a block translation, which makes use of placeholders to
-help translators to translate an entire sentence. To translate a
-block, Jinja2 uses the [trans][trans] tag. So rather than writing
-something ugly and confusing for translators like this:
+If a piece of text contains both a literal string component and variables, use a
+block translation. This puts in placeholders for variables, to allow translators
+to translate an entire sentence.
+
+To tag a block for translation, Jinja2 uses the [trans][trans] tag, like this:
```jinja
-# Don't do this!
-{{ _("This string will have") }} {{ value }} {{ _("inside") }}
+{% trans %}This string will have {{ value }} inside.{% endtrans %}
```
-You can instead use:
+Never break up a sentence like this, as it will make it impossible to translate
+correctly:
```jinja
-{% trans %}This string will have {{ value }} inside.{% endtrans %}
+# Don't do this!
+{{ _("This string will have") }} {{ value }} {{ _("inside") }}
```
-### Python
+#### Python
A string in Python can be marked for translation using the `_()` function,
which can be imported as follows:
@@ -205,7 +155,7 @@ class Realm(models.Model):
To ensure we always internationalize our JSON error messages, the
Zulip linter (`tools/lint`) attempts to verify correct usage.
-## Frontend translations
+### Frontend translations
We use the [FormatJS][] library for frontend translations when dealing
with [Handlebars][] templates or JavaScript.
@@ -251,7 +201,7 @@ $t_html(
)
```
-### Handlebars templates
+#### Handlebars templates
For translations in Handlebars templates we also use FormatJS, through two
Handlebars [helpers][] that Zulip registers. The syntax for simple strings is:
@@ -308,12 +258,68 @@ custom HTML tag like this:
{{/tr}}
```
-## Transifex config
+## Translation process
+
+The end-to-end tooling process for translations in Zulip is as follows.
+
+1. The strings are marked for translation (see sections for
+ [backend](#backend-translations) and
+ [frontend](#frontend-translations) translations for details on
+ this).
+
+2. Translation resource files are created using the
+ `./manage.py makemessages` command. This command will create, for
+ each language, a resource file called `translations.json` for the
+ frontend strings and `django.po` for the backend strings.
+
+ The `makemessages` command is idempotent in that:
+
+ - It will only delete singular keys in the resource file when they
+ are no longer used in Zulip code.
+ - It will only delete plural keys (see above for the documentation
+ on plural translations) when the corresponding singular key is
+ absent.
+ - It will not override the value of a singular key if that value
+ contains a translated text.
+
+3. Those resource files are uploaded to Transifex by a maintainer using the
+ `./tools/i18n/push-translations` command (which invokes a Transifex
+ API tool, `tx push`, internally).
+
+4. Translators translate the strings in the Transifex UI. (In theory,
+ it's possible to translate locally and then do `tx push`, but
+ because our workflow is to sync translation data from Transifex to
+ Zulip, making changes to translations in Zulip risks having the
+ changes blown away by a data sync, so that's only a viable model
+ for a language that has no translations yet).
+
+5. The translations are downloaded back into the codebase by a
+ maintainer, using `tools/i18n/sync-translations` (which invokes the
+ Transifex API tool, `tx pull`, internally).
+
+If you're interested, you may also want to check out the [translators'
+workflow](translating.md#translators-workflow), just so you have a
+sense of how everything fits together.
+
+## Translation resource files
+
+All the translation magic happens through resource files, which hold
+the translated text. Backend resource files are located at
+`locale/<lang_code>/LC_MESSAGES/django.po`, while frontend
+resource files are located at
+`locale/<lang_code>/translations.json` (and mobile at
+`mobile.json`).
+
+These files are uploaded to [Transifex][], where they can be translated.
+
+## Working with Transifex
+
+### Transifex config
The config file that maps the resources from Zulip to Transifex is
located at `.tx/config`.
-## Transifex CLI setup
+### Transifex CLI setup
In order to be able to run `tx pull` (and `tx push` as well, if you're a
maintainer), you have to specify your Transifex API Token, [generated in
@@ -332,6 +338,13 @@ token = 1/abcdefg...
This basically identifies you as a Transifex user, so you can access your
organizations from the command line.
+## Additional resources
+
+We recommend the [EdX i18n guide][edx-i18n] as a great resource for learning
+more about internationalization in general; we agree with essentially all of
+their style guidelines.
+
+[edx-i18n]: https://docs.openedx.org/en/latest/developers/references/developer_guide/internationalization/i18n.html
[jinja2]: http://jinja.pocoo.org/
[handlebars]: https://handlebarsjs.com/
[trans]: https://jinja.palletsprojects.com/en/3.0.x/extensions/#i18n-extension
diff --git a/docs/translating/translating.md b/docs/translating/translating.md
index 64f1323019c..f638b045ef9 100644
--- a/docs/translating/translating.md
+++ b/docs/translating/translating.md
@@ -1,6 +1,6 @@
# Translation guidelines
-Zulip's has full support for Unicode (and partial support for RTL
+Zulip has full support for Unicode (and partial support for RTL
languages), so you can use your preferred language everywhere in
Zulip.