Merge lp:~widelands-dev/widelands/bug-1324137 into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7074
Proposed branch: lp:~widelands-dev/widelands/bug-1324137
Merge into: lp:widelands
Diff against target: 174 lines (+81/-13)
1 file modified
doc/sphinx/source/tutorial.rst (+81/-13)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1324137
Reviewer Review Type Date Requested Status
SirVer Approve
Review via email: mp+221353@code.launchpad.net

Description of the change

Added documentation for string design

To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

some suggestions.

review: Needs Fixing
Revision history for this message
GunChleoc (gunchleoc) wrote :

Somments to the suggestions

Revision history for this message
GunChleoc (gunchleoc) wrote :

Added some fixes. Some issues are still open.

Revision history for this message
SirVer (sirver) :
review: Approve
Revision history for this message
SirVer (sirver) :
review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

I have found a better example for the plural forms (en "cat" = gd "cat"). I think this is ready for merging now.

Revision history for this message
SirVer (sirver) wrote :

Cool! Merged in r 7074.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'doc/sphinx/source/tutorial.rst'
2--- doc/sphinx/source/tutorial.rst 2013-04-03 09:06:34 +0000
3+++ doc/sphinx/source/tutorial.rst 2014-07-11 17:14:51 +0000
4@@ -5,7 +5,7 @@
5
6 This section describes how to get a map ready for scripting addition and how
7 to write simple Lua scripts. It goes trough all the concepts required to get
8-you started writing cool widelands scenarios and campaigns.
9+you started writing cool widelands scenarios and campaigns.
10
11 Designing the Map
12 -----------------
13@@ -14,7 +14,7 @@
14 that describe a map. Normally, widelands saves those files in one zip archive
15 file with the file extension ``.wmf``. To add scripting capabilities to maps,
16 we have to create new text files in the ``scripting/`` directory of the map,
17-therefore we want to have the map as a plain directory, so that we can
18+therefore we want to have the map as a plain directory, so that we can
19 easily add new scripting files. There are two ways to achieve this:
20
21 1. Set the nozip option in the advanced options inside of Widelands.
22@@ -36,7 +36,7 @@
23 following inside:
24
25 .. code-block:: lua
26-
27+
28 print "###############################"
29 print "Hello World"
30 print "###############################"
31@@ -74,19 +74,19 @@
32
33 So what we learned is that widelands will run the script
34 ``scripting/init.lua`` as soon as the map is finished loading. This script is
35-the entry point for all scripting inside of widelands.
36+the entry point for all scripting inside of widelands.
37
38-.. _`Lua`: http://www.lua.org/
39+.. _`Lua`: http://www.lua.org/
40
41 A Lua Primer
42 ------------
43
44 This section is intentionally cut short. There are excellent tutorials in
45 `Luas Wiki`_ and there is a complete book free online: `Programming in Lua`_.
46-You should definitively start there to learn Lua.
47+You should definitively start there to learn Lua.
48
49 This section only contains the parts of Lua that I found bewildering and it
50-also defines a few conventions that are used in this documentation.
51+also defines a few conventions that are used in this documentation.
52
53 .. _`Luas Wiki`: http://lua-users.org/wiki/TutorialDirectory
54 .. _`Programming in Lua`: http://www.lua.org/pil/
55@@ -103,7 +103,7 @@
56
57 .. code-block:: lua
58
59- d = {
60+ d = {
61 value_a = 23,
62 b = 34,
63 90 = "Hallo"
64@@ -137,7 +137,7 @@
65 surprise for most programmers is that Lua throws values away without notice.
66
67 .. code-block:: lua
68-
69+
70 function f(a1, a2, a3) print("Hello World:", a1, a2, a3) end
71
72 f() --- Prints 'Hello World: nil nil nil'
73@@ -190,7 +190,7 @@
74 use them watered down and very simple, but their power is enormous. In
75 Widelands use case, a coroutine is simply a function that can interrupt it's
76 execution and give control back to widelands at any point in time. After
77-it is awoken again by widelands, it will resume at precisely the same point
78+it is awoken again by widelands, it will resume at precisely the same point
79 again. Let's dive into an example right away:
80
81 .. code-block:: lua
82@@ -211,14 +211,14 @@
83 digest this example. The first line imports the ``coroutine.lua`` script from
84 the auxiliary Lua library that comes bundled with widelands. We use two
85 functions from this in the rest of the code, namly :func:`sleep` and
86-:func:`run`.
87+:func:`run`.
88
89 Then we define a simple function :func:`print_a_word` that takes one argument
90 and enters an infinite loop: it prints the argument, then sleeps for a second.
91 The :func:`sleep` function puts the coroutine to sleep and tells widelands to
92 wake the coroutine up again after 1000 ms have passed. The coroutine will then
93 continue its execution directly after the sleep call, that is it will enter
94-the loop's body again.
95+the loop's body again.
96
97 All we need now is to get this function started and this is done via the
98 :func:`run` function: it takes as first argument a function and then any
99@@ -267,6 +267,74 @@
100 The first coroutine will print out the current value of a, the second changes
101 the value of the variable a asynchronously. So we see in this example that
102 coroutines share the same environment and can therefore use global variables
103-to communicate with each other.
104+to communicate with each other.
105+
106+
107+Preparing Strings for Translation
108+---------------------------------
109+
110+If you want your scenario to be translatable into different languages, it is important to keep in mind that languages differ widely in their grammar. This entails that word forms and word order will change, and some languages have more than one plural form. So, here are some pointers for good string design. For examples for the formatting discussed here, have a look at ``maps/MP Scenarios/Island Hopping.wmf/scripting/multiplayer_init.lua`` in the source code.
111+
112+Marking a String for Translation
113+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
114+
115+In order to tell Widelands to add a string to the list of translatable strings, simply add an underscore in front of it, like this:
116+
117+.. code-block:: lua
118+
119+ print _"Translate me"
120+
121+Strings that contain number variables have to be treated differently; cf. the ``Numbers in Placeholders`` section below.
122+
123+Translator Comments
124+^^^^^^^^^^^^^^^^^^^
125+
126+If you have a string where you feel that translators will need a bit of help to understand what it does, you can add a translator comment to it. Translator comments are particularly useful when you are working with placeholders, because you can tell the translator what the placeholder will be replaced with. Translator comments need to be inserted into the code in the line directly above the translation. Each line of a translator comment has to be prefixed by ``-- TRANSLATORS: ``, like this:
127+
128+.. code-block:: lua
129+
130+ -- TRANSLATORS: This is just a test string
131+ -- TRANSLATORS: With a multiline comment
132+ print _"Hello Word"
133+
134+
135+Working with Placeholders
136+^^^^^^^^^^^^^^^^^^^^^^^^^
137+
138+If you have multiple variables in your script that you wish to include dynamically in the same string, please use ordered placeholders to give translators control over the word order. We have implemented a special Lua function for this called `bformat <https://wl.widelands.org/docs/wl/autogen_globals/#string.bformat>`_ that works just like the ``boost::format`` function in C++. Example:
139+
140+.. code-block:: lua
141+
142+ local world = _("world") -- Will print in Gaelic: "saoghal"
143+ local hello = _("hello") -- Will print in Gaelic: "halò"
144+ -- TRANSLATORS: %1$s = hello, %2$s = world
145+ print (_ "The %1$s is '%2$s'"):bformat(hello, world) -- Will print in Gaelic: "Is 'halò' an saoghal"
146+
147+
148+Numbers in Placeholders
149+^^^^^^^^^^^^^^^^^^^^^^^
150+
151+Not all languages' number systems work the same as in English. For example, the Gaelic word for "cat" conveniently is "cat", and this is how its plural works: `0 cat`, `1 or 2 chat`, `3 cait`, `11 or 12 chat`, `13 cait`, `20 cat`... So, instead of using ``_`` to fetch the translation, any string containing a placeholder that is a number should be fetched with ``ngettext`` instead. First, you fetch the correct plural form, using the number variable and ``ngettext``:
152+
153+.. code-block:: lua
154+
155+ pretty_plurals_string = ngettext("There is %s world" , "There are %s worlds", number_of_worlds)
156+
157+
158+Then you still need to format the string with your variable:
159+
160+.. code-block:: lua
161+
162+ print pretty_plurals_string:format(number_of_worlds)
163+
164+If you have a string with multiple numbers in it that would trigger plural forms, split it into separate strings that you can fetch with ``ngettext``. You can then combine them with ``bformat`` and ordered placeholders.
165+
166+
167+Handling Long Strings
168+^^^^^^^^^^^^^^^^^^^^^
169+
170+If you have a really long string, e.g. a dialog stretching over multiple sentences, check if there is a logical place where you could split this into two separate strings for translators. We don't have a "break after x characters" rule for this; please use common sense here. It is easier for translators to translate smaller chunks, and if you should have to change the string later on, e.g. to fix a typo, you will break less translations. The strings will be put into the translation files in the same order as they appear in the source code, so the context will remain intact for the translators.
171+
172+Also, please hide all formatting control characers from our translators. This includes HTML tags as well as new lines in the code! For an example, have a look at ``campaigns/atl01.wmf/scripting/texts.lua``
173
174 .. vim:ft=rst:spelllang=en:spell

Subscribers

People subscribed via source and target branches

to status/vote changes: