Skip to content

Commit 2f15bcc

Browse files
stevepiercyerral
andauthored
Modernize i18n workflow (#1999)
* Modernize i18n workflow * Apply suggestions from code review Co-authored-by: Mikel Larreategi <[email protected]> * Remove obsolete buildout section * Add some MyST markup --------- Co-authored-by: Mikel Larreategi <[email protected]>
1 parent f4d7507 commit 2f15bcc

File tree

2 files changed

+23
-49
lines changed

2 files changed

+23
-49
lines changed

docs/glossary.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ Buildout
2525
[Buildout](https://github.com/buildout/buildout/) is a Python-based tool for building and assembling applications from multiple parts, based on a configuration file.
2626
It was the most common way of installing Plone 3, 4, and 5, and can still be used with Plone 6.
2727
28+
Usage of Buildout in Plone appears in various places in this documentation.
29+
For a history and extended usage of Buildout, you can refer to the Plone 4 Documentation's section on [Buildout](https://4.docs.plone.org/old-reference-manuals/buildout/).
30+
The Plone community authored this reference manual, as Buildout's own documentation is suboptimal.
31+
2832
CMS
2933
Content Management System
3034

docs/i18n-l10n/translating-text-strings.md

Lines changed: 19 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Plone internally uses the UNIX standard {term}`gettext` tool to perform {term}`i
3434
The package `zope.i18n` implements several APIs related to internationalization and localization.
3535

3636
- Follows {term}`gettext` best practices.
37-
- Translations are stored in the `locales` folder of your application, such as `locales/fi/LC_MESSAGES/your.app.po`.
37+
- Translations are stored in the `locales` folder of your application, such as {file}`locales/fi/LC_MESSAGES/your.app.po`.
3838
- Uses the package [`zope.i18nmessageid`](https://pypi.org/project/zope.i18nmessageid/).
3939
This provides a string-like class which allows storing the translation domain with translatable text strings.
4040
- {term}`PO file`s must usually be manually converted to binary {term}`MO file`s every time the translations are updated.
@@ -56,11 +56,15 @@ Information in the PO file headers is ignored.
5656

5757
[`i18ndude`](https://pypi.org/project/i18ndude/) should be used to create a script which searches particular packages for translation strings.
5858

59-
If you have created your add-on using [bobtemplates.plone](https://pypi.org/project/bobtemplates.plone/), then you will already have a script `update.sh` inside your package and a script `update_locale` in your buildout to extract the messages from your code.
59+
If you have created your add-on using [`bobtemplates.plone`](https://pypi.org/project/bobtemplates.plone/), then you will already have a script {file}`update.sh` inside your package and a script {file}`update_locale` in your {term}`buildout` to extract the messages from your code.
6060

61-
After running that script, a new `domain.pot` file will be created in your `locales` directory where all the messages will be saved.
61+
If you have created your add-on or projects using [Cookieplone](https://github.com/plone/cookieplone), then you will already have a `make i18n` command in the {file}`backend` folder that extracts the messages from your code.
6262

63-
To have those messages translated into some languages, you will need to create a language directory inside the `locales` directory, and a `LC_MESSAGES` directory inside it.
63+
This command will call `i18ndude` under the hood using `uvx`, without you needing to install it separately.
64+
65+
After running that script, a new {file}`domain.pot` file will be created in your {file}`locales` directory where all the messages will be saved.
66+
67+
To have those messages translated into some languages, you will need to create a language directory inside the {file}`locales` directory, and a {file}`LC_MESSAGES` directory inside it.
6468
This follows the gettext standard.
6569
After doing that, the directory structure will be as follows.
6670

@@ -70,11 +74,11 @@ After doing that, the directory structure will be as follows.
7074
./locales/ga/LC_MESSAGES/domain.po
7175
```
7276

73-
You will need to provide your translations in those `domain.po` files.
77+
You will need to provide your translations in those {file}`domain.po` files.
7478

75-
If you add, update, or remove strings in your package, you will need to run only the `update.sh` script to update all language files.
79+
If you add, update, or remove strings in your package, you will need to run only the {file}`update.sh` script to update all language files.
7680

77-
You also need to have the following ZCML entry to signal Plone that the files stored in the `locales` folder follow the gettext standard and that it needs to use them when requesting translated strings.
81+
You also need to have the following ZCML entry to signal Plone that the files stored in the {file}`locales` folder follow the gettext standard and that it needs to use them when requesting translated strings.
7882

7983
```xml
8084
<configure xmlns:i18n="http://namespaces.zope.org/i18n">
@@ -89,7 +93,7 @@ You also need to have the following ZCML entry to signal Plone that the files st
8993

9094
You will need to declare you own `MessageFactory`.
9195
This is a callable that marks strings with a translation domain.
92-
`MessageFactory` is usually declared in the main `__init__.py` file of your package.
96+
`MessageFactory` is usually declared in the main {file}`__init__.py` file of your package.
9397
It is imported from wherever it is needed in your package.
9498
`_` is the standard name that is used in gettext to identify the translation function, and the previous scripts will use that assumption to identify translatable strings.
9599

@@ -155,7 +159,7 @@ It will use the text content of the element as `msgid`.
155159
Use attributes `i18n:translate`, `i18n:attributes`, and so on.
156160
For examples, look at any core Plone `.pt` files.
157161

158-
The `i18n:translate` attribute will {term}`hook` into the translation machinery, and will look up the corresponding translated string to the one stated there, while looking in the relevant `domain.po` file corresponding to the `i18n:domain` stated in the file and the language negotiated by Plone.
162+
The `i18n:translate` attribute will {term}`hook` into the translation machinery, and will look up the corresponding translated string to the one stated there, while looking in the relevant {file}`domain.po` file corresponding to the `i18n:domain` stated in the file and the language negotiated by Plone.
159163

160164

161165
(translating-text-strings-automatically-translated-message-ids-label)=
@@ -269,40 +273,6 @@ To make this easier, and if you use [zest.releaser](https://pypi.org/project/zes
269273
This script hooks into the release process and builds the MO files for you.
270274

271275

272-
(translating-text-strings-installing-i18ndude-label)=
273-
274-
### Installing i18ndude
275-
276-
The recommended method is to have {term}`i18ndude` installed via your [buildout](https://www.buildout.org/en/latest/).
277-
278-
Add the following to your `buildout.cfg`:
279-
280-
```cfg
281-
parts =
282-
...
283-
i18ndude
284-
285-
[i18ndude]
286-
unzip = true
287-
recipe = zc.recipe.egg
288-
eggs = i18ndude
289-
```
290-
291-
After running buildout, `i18ndude` will be available in your `buildout/bin` folder.
292-
293-
```console
294-
bin/i18ndude -h
295-
Usage: i18ndude command [options] [path | file1 file2 ...]]
296-
```
297-
298-
You can also call it relative to your current package source folder.
299-
300-
```console
301-
server:home moo$ cd src/mfabrik.plonezohointegration/
302-
server:mfabrik.plonezohointegration moo$ ../../bin/i18ndude
303-
```
304-
305-
306276
(translating-text-strings-setting-up-folder-structure-for-finnish-and-english-label)=
307277

308278
### Setting up folder structure for Finnish and English
@@ -336,9 +306,9 @@ i18ndude rebuild-pot --pot locales/mydomain.pot --create your.app.package .
336306
`i18ndude` scans source `.py` and `.pt` files for translatable text strings.
337307
On some occasions this is not enough, for example, when you dynamically generate message IDs in your code.
338308
Entries which cannot be detected by an automatic code scan are called {term}`manual .po entries`.
339-
They are managed in `locales/manual.pot`, which is merged into the generated `locales/yournamespace.app.pot` file.
309+
They are managed in {file}`locales/manual.pot`, which is merged into the generated {file}`locales/yournamespace.app.pot` file.
340310

341-
Here is a sample `manual.pot` file.
311+
Here is a sample {file}`manual.pot` file.
342312

343313
```po
344314
msgstr ""
@@ -404,11 +374,11 @@ https://web.archive.org/web/20131018150303/http://permalink.gmane.org/gmane.comp
404374

405375
If you need to change a translation from a PO file, you could create a new Python package and register your own PO files.
406376

407-
To do this, create the package and add a `locales` directory in there, along the lines of what [plone.app.locales](https://pypi.org/project/plone.app.locales/) does.
377+
To do this, create the package and add a {file}`locales` directory in there, along the lines of what [`plone.app.locales`](https://pypi.org/project/plone.app.locales/) does.
408378
Then you can add your own translations in the language that you need.
409-
For example, `locales/fr/LC_MESSAGES/plone.po` overrides French messages in the `plone` domain.
379+
For example, {file}`locales/fr/LC_MESSAGES/plone.po` overrides French messages in the `plone` domain.
410380

411-
Reference the translation in `configure.zcml` of your package:
381+
Reference the translation in {file}`configure.zcml` of your package:
412382

413383
```xml
414384
<configure xmlns:i18n="http://namespaces.zope.org/i18n"
@@ -417,7 +387,7 @@ Reference the translation in `configure.zcml` of your package:
417387
</configure>
418388
```
419389

420-
Your ZCML needs to be included *before* the one from [plone.app.locales](https://pypi.org/project/plone.app.locales/).
390+
Your ZCML needs to be included *before* the one from [`plone.app.locales`](https://pypi.org/project/plone.app.locales/).
421391
The first translation of a `msgid` wins.
422392
To manage this, you can include the ZCML in the buildout:
423393

0 commit comments

Comments
 (0)