aboutsummaryrefslogtreecommitdiff
path: root/documentation/content/en/books/fdp-primer/po-translations/_index.adoc
blob: 279803ce06b9a419f69a74d3b2ca27bc3f3a2418 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
---
title: Chapter 9. PO Translations
prev: books/fdp-primer/translations
next: books/fdp-primer/weblate
description: How to work with PO translation in the FreeBSD Documentation Project
tags: ["po", "translations", "tutorial", "quick start"]
showBookMenu: true
weight: 9
path: "/books/fdp-primer/po-translations/"
---

[[po-translations]]
= PO Translations
:doctype: book
:toc: macro
:toclevels: 1
:icons: font
:sectnums:
:sectnumlevels: 6
:sectnumoffset: 9
:partnums:
:source-highlighter: rouge
:experimental:
:images-path: books/fdp-primer/

ifdef::env-beastie[]
ifdef::backend-html5[]
:imagesdir: ../../../../images/{images-path}
endif::[]
ifndef::book[]
include::shared/authors.adoc[]
include::shared/mirrors.adoc[]
include::shared/releases.adoc[]
include::shared/attributes/attributes-{{% lang %}}.adoc[]
include::shared/{{% lang %}}/teams.adoc[]
include::shared/{{% lang %}}/mailing-lists.adoc[]
include::shared/{{% lang %}}/urls.adoc[]
toc::[]
endif::[]
ifdef::backend-pdf,backend-epub3[]
include::../../../../../shared/asciidoctor.adoc[]
endif::[]
endif::[]

ifndef::env-beastie[]
toc::[]
include::../../../../../shared/asciidoctor.adoc[]
endif::[]

[[po-translations-introduction]]
== Introduction

The http://www.gnu.org/software/gettext/[GNU gettext] system offers translators an easy way to create and maintain translations of documents.
Translatable strings are extracted from the original document into a PO (Portable Object) file.
Translated versions of the strings are entered with a separate editor.
The strings can be used directly or built into a complete translated version of the original document.

[[po-translations-quick-start]]
== Quick Start

The procedure shown in crossref:overview[overview-quick-start,Quick Start] is assumed to have already been performed.
The `TRANSLATOR` option is required and already enabled by default in the package:textproc/docproj[] port.

This example shows the creation of a Spanish translation of the short extref:{leap-seconds}[Leap Seconds] article.

[[po-translations-quick-start-install-po-editor]]

[.procedure]
====
.Procedure: Install a PO Editor
. A PO editor is needed to edit translation files. This example uses package:editors/poedit[].
+
[source,shell]
....
# pkg install poedit
....
====

[[po-translations-quick-start-initial-setup]]
[.procedure]
====
.Procedure: Initial Setup

When a new translation is first created, the directory structure must be created or copied from the English original:

. Create a directory for the new translation. The English article source is in [.filename]#~/doc/documentation/content/en/articles/leap-seconds/#. The Spanish translation will go in [.filename]#~/doc/documentation/content/es/articles/leap-seconds/#. The path is the same except for the name of the language directory.
The English article source is in [.filename]#~/doc/en/articles/leap-seconds/#.
The Spanish translation will go in [.filename]#~/doc/es/articles/leap-seconds/#.
The path is the same except for the name of the language directory.
+
[source,shell]
....
% mkdir ~/doc/documentation/content/es/articles/leap-seconds
....

. Copy the [.filename]#_index.po# from the original document into the translation directory:
+
[source,shell]
....
% cp ~/doc/documentation/content/en/articles/leap-seconds/_index.po \
  ~/doc/documentation/content/es/articles/leap-seconds/
....

Suppose the document or language is also being translated via Weblate.
In that case, it is good to get the `.po` file from there and upload the translation document back into the platform, centralizing the translating efforts via Weblate to avoid rework.

See how to download the `.po` files in the crossref:weblate[weblate-translating-offline,Translating Offline on Weblate] chapter.
====

[[po-translations-quick-start-translation]]
[.procedure]
====
.Procedure: Translation

Use a PO editor to enter translations in the PO file.
There are several different editors available. [.filename]#poedit# from package:editors/poedit[] is shown here.

[source,shell]
....
% poedit documentation/content/es/articles/leap-seconds/_index.po
....
====

[[po-translations-quick-generating-a-translated-document]]
[.procedure]
====
.Procedure: Generating a Translated Document
. Generate the translated document:
+
[source,shell]
....
% cd ~/doc
% ./tools/translate.sh documentation es articles/leap-seconds
....
+
The name of the generated document matches the name of the English original, usually [.filename]#_index.adoc#.
+
. Check the generated file by rendering it to HTML and viewing it with a web browser:
+
[source,shell]
....
% cd ~/doc/documentation
% make
....
====

[[po-translations-creating]]
== Creating New Translations

The first step to creating a new translated document is locating or creating a directory to hold it.
FreeBSD puts translated documents in a subdirectory named for their language and region in the format [.filename]#lang#.
_lang_ is a two-character lowercase code.

[[po-translations-language-names]]
.Language Names
[cols="1,1,1", frame="none", options="header"]
|===
| Language
| Region
| Translated Directory Name

|English
|United States
|[.filename]#en#

|Bengali
|Bangladesh
|[.filename]#bn-bd#

|Danish
|Denmark
|[.filename]#da#

|German
|Germany
|[.filename]#de#

|Greek
|Greece
|[.filename]#el#

|Spanish
|Spain
|[.filename]#es#

|French
|France
|[.filename]#fr#

|Hungarian
|Hungary
|[.filename]#hu#

|Italian
|Italy
|[.filename]#it#

|Japanese
|Japan
|[.filename]#ja#

|Korean
|Korea
|[.filename]#ko#

|Mongolian
|Mongolia
|[.filename]#mn#

|Dutch
|Netherlands
|[.filename]#nl#

|Polish
|Poland
|[.filename]#pl#

|Portuguese
|Brazil
|[.filename]#pt-br#

|Russian
|Russia
|[.filename]#ru#

|Turkish
|Turkey
|[.filename]#tr#

|Chinese
|China
|[.filename]#zh-cn#

|Chinese
|Taiwan
|[.filename]#zh-tw#
|===

The translations are in subdirectories of the main documentation directory,
here assumed to be [.filename]#~/doc/documentation/# as shown in crossref:overview[overview-quick-start, Quick Start].
For example, German translations are located in [.filename]#~/doc/documentation/content/de/#,
and French translations are in [.filename]#~/doc/documentation/content/fr/#.

Each language directory contains separate subdirectories named for the type of documents, usually [.filename]#articles/# and [.filename]#books/#.

Combining these directory names gives the complete path to an article or book.
For example, the French translation of the NanoBSD article is in [.filename]#~/doc/documentation/content/fr/articles/nanobsd/#,
and the Mongolian translation of the Handbook is in [.filename]#~/doc/documentation/content/mn/books/handbook/#.

A new language directory must be created when translating a document to a new language.
If the language directory already exists, only a subdirectory in the [.filename]#articles/# or [.filename]#books/# directory is needed.

[[po-translations-creating-example]]
.Creating a Spanish Translation of the Porter's Handbook
[example]
====
Create a new Spanish translation of the extref:{porters-handbook}[Porter's Handbook].
The original is a book in [.filename]#~/doc/documentation/content/en/books/porters-handbook/#.

[.procedure]
======

. The Spanish language books directory [.filename]#~/doc/documentation/content/es/books/# already exists, so only a new subdirectory for the Porter's Handbook is needed:
+
[source,shell]
....
% cd ~/doc/documentation/content/es/books
% mkdir porters-handbook
....

. Copy the content from the original book:
+
[source,shell]
....
% cd porters-handbook
% cp -R ~/doc/documentation/content/en/books/porters-handbook/* .
....
+
Now the document structure is ready for the translator to begin translating with `po4a` command.
======
====

[[po-translations-translating]]
== Translating

The gettext system greatly reduces the number of things that must be tracked by a translator.
Strings to be translated are extracted from the original document into a PO file.
Then a PO editor is used to enter the translated versions of each string.

The FreeBSD PO translation system does not overwrite PO files, so the extraction step can be run at any time to update the PO file.

A PO editor is used to edit the file.
package:editors/poedit[] is shown in these examples because it is simple and has minimal requirements.
Other PO editors offer features to make the job of translating easier.
The Ports Collection offers several of these editors, including package:devel/gtranslator[].

It is important to preserve the PO file.
It contains all of the work that translators have done.

[IMPORTANT]
====
Translating documents online proves to be the easiest method for document translation on FreeBSD, as it allows multiple users to collaborate on the same file, distributing the workload effectively.
For more details, please refer to the next chapter, crossref:weblate[weblate-introduction,Weblate Translations].
====

[[po-translations-tips]]
== Tips for Translators

[[po-translations-tips-xmltags]]
=== Preserving AsciiDoc macros

Preserve AsciiDoc macros that are shown in the English original.

.Preserving AsciiDoc macros
[example]
====
English original:

[.programlisting]
....
msgid ""
"This example shows the creation of a Spanish translation of the short "
"extref:{leap-seconds}[Leap Seconds] article."
....

Spanish translation:

[.programlisting]
....
msgid ""
"Este ejemplo muestra la creación de un artículo con poco contenido como el artículo "
"extref:{leap-seconds}[Leap Seconds]."
....

====

[[po-translations-tips-spaces]]
=== Preserving Spaces

Preserve existing spaces at the beginning and end of strings to be translated.
The translated version must have these spaces also.

[[po-translations-tips-verbatim]]
=== Verbatim Tags

The contents of some tags should be copied verbatim, not translated:

* `man:man[1]`
* `package:package[]`
* `link`
* `image`
* `include`
* `Admonitions`
* `id's`
* `Heading tags`
* `source`

[[po-translations-building]]
== Building a Translated Document

A translated version of the original document can be created at any time.
Any untranslated portions of the original will be included in English in the resulting document.
Most PO editors have an indicator that shows how much of the translation has been completed.
This makes it easy for the translator to see when enough strings have been translated to make building the final document worthwhile.

The Weblate chapter provides a complete example of how to crossref:weblate[weblate-building,Build the Translated Document].

[[po-translations-submitting]]
== Submitting the New Translation

Prepare the new translation files for submission.
This includes adding the files to the version control system, setting additional properties on them, then creating a diff for submission.

The diff files created by these examples can be attached to a https://bugs.freebsd.org/bugzilla/enter_bug.cgi?product=Documentation[documentation bug report] or https://reviews.freebsd.org/[code review].

[[po-translations-submitting-spanish]]
.Spanish Translation of the NanoBSD Article
[example]
====
[.procedure]
======

. Create a diff of the new files from the [.filename]#~/doc/# base directory so the full path is shown with the filenames. This helps committers identify the target language directory.
+
[source,shell]
....
% cd ~/doc
% git diff documentation/content/es/articles/nanobsd/ > /tmp/es_nanobsd.diff
....
======

The Weblate chapter provides a complete example of how to crossref:weblate[weblate-submitting-translations,Submit the New Translation].

====