2010-09-29 21:35:21 -04:00
|
|
|
Utilities
|
|
|
|
|
2016-09-30 10:46:56 -04:00
|
|
|
typo.php - is a crude syntax checker to avoid checking in files with simple
|
|
|
|
typos. It basically just loads each of our project files at once. Run from
|
2010-09-29 21:35:21 -04:00
|
|
|
cmdline and see if any parsing errors are reported.
|
|
|
|
|
2010-11-20 18:23:41 -05:00
|
|
|
|
|
|
|
|
|
|
|
Internationalisation
|
|
|
|
|
2016-09-30 10:46:56 -04:00
|
|
|
extract.php - extracts translatable strings from our project files. It
|
|
|
|
currently doesn't pick up strings in other libraries we might be using such as
|
2017-01-26 22:58:25 -05:00
|
|
|
the HTML parsers.
|
2010-09-29 21:35:21 -04:00
|
|
|
|
2018-01-22 07:29:50 -05:00
|
|
|
In order for extract to do its job, every use of the L10n::t() translation function
|
2010-09-29 21:35:21 -04:00
|
|
|
must be preceded by one space. The string also can not contain parentheses. If
|
2010-10-06 20:40:58 -04:00
|
|
|
parens are required in a string which requires translation, please use hex escapes.
|
|
|
|
|
|
|
|
\x28 = (
|
|
|
|
\x29 = )
|
|
|
|
|
2016-09-30 10:46:56 -04:00
|
|
|
This only applies to English. Other languages may use parens in strings
|
2010-11-20 18:23:41 -05:00
|
|
|
because they don't require extraction.
|
2016-09-30 10:46:56 -04:00
|
|
|
|
2010-09-29 21:35:21 -04:00
|
|
|
strings.php - a recent run of the strings program. This provides output that
|
2016-09-30 10:46:56 -04:00
|
|
|
is suitable for direct inclusion in the program.
|
2010-09-29 21:35:21 -04:00
|
|
|
|
2016-09-30 10:46:56 -04:00
|
|
|
There are also translatable strings in the various files in the view/lang/en
|
|
|
|
directory. By setting $lang = 'something' in .htconfig.php, the application
|
|
|
|
will search for view/lang/something/filename prior to the English version in
|
|
|
|
view/lang/en/filename when loading templates and view files.
|
2010-11-20 18:23:41 -05:00
|
|
|
|
2016-09-30 10:46:56 -04:00
|
|
|
The translated string table should be placed in view/lang/$lang/strings.php for
|
2010-11-20 18:23:41 -05:00
|
|
|
automatic inclusion.
|
2010-10-06 20:40:58 -04:00
|
|
|
|
|
|
|
You are not restricted to using known languages. You may also use this to
|
|
|
|
translate the software into "pirate", "surfer" or merely to replace certain
|
2016-09-30 10:46:56 -04:00
|
|
|
text which you don't care for.
|
2010-10-06 20:40:58 -04:00
|
|
|
|
2016-09-30 10:46:56 -04:00
|
|
|
Note: The view/lang/en directory contains many HTML template files, some of which
|
2010-11-20 18:23:41 -05:00
|
|
|
only have a few words of English text amongst the HTML. Over time we will move
|
2016-09-30 10:46:56 -04:00
|
|
|
the translation to the replace_macros() function which calls these files and
|
|
|
|
then relocate the files to the view directory. The files in the top-level view
|
|
|
|
directory are template files which do not require translation.
|
2010-09-29 21:35:21 -04:00
|
|
|
|
|
|
|
|
2011-03-18 07:36:34 -04:00
|
|
|
Placeholders
|
|
|
|
|
|
|
|
Do not translate placeholders in strings! Things like %s, %d, %1$s and $somename
|
|
|
|
are used to add dynamic content to the string.
|
|
|
|
|
2011-03-19 08:10:05 -04:00
|
|
|
%s represents a dynamic string, like in "Welcome to %s"
|
|
|
|
%d represents a dynamic number, like in "%d new messages"
|
2011-03-18 07:36:34 -04:00
|
|
|
$somename is a variable like in php
|
|
|
|
In %1$s %2$s, the numbers are the position index of multiple dynamic content.
|
|
|
|
You could swap position in string of indexed placeholders.
|
|
|
|
e.g.
|
|
|
|
"%1$s's %2$s" => "John's photo", "John's item"
|
|
|
|
"%2$s di %1$s" => "foto di John", "elemento di John"
|
|
|
|
|
|
|
|
|
|
|
|
Plural
|
|
|
|
|
2018-01-21 17:15:52 -05:00
|
|
|
The L10n::tt() function supports plural form. Script extract.php write this in
|
2011-03-18 07:36:34 -04:00
|
|
|
strings.php as an array, one string for every plural form language supports:
|
|
|
|
|
|
|
|
$a->string["%d message sent"] = Array(
|
|
|
|
0 => "%d message sent",
|
|
|
|
1 => "%d messages sent",
|
|
|
|
);
|
|
|
|
|
|
|
|
The function string_plural_select($n) defined in strings.php, return the string
|
|
|
|
index to use, related to the numbers of item (value of $n).
|
|
|
|
|
2018-03-18 23:44:27 -04:00
|
|
|
This is modeled after ngettext function of GNU gettext.
|
2011-03-18 07:36:34 -04:00
|
|
|
More info at http://www.gnu.org/software/hello/manual/gettext/Plural-forms.html
|
|
|
|
|
|
|
|
|
|
|
|
Xgettext and .po workflow
|
|
|
|
|
2011-03-19 08:10:05 -04:00
|
|
|
1. Run util/run_xgettext.sh script (on *unix sistems, with GNU xgettext installed)
|
2018-01-21 17:15:52 -05:00
|
|
|
This script runs xgettext on source tree, extracting strings from L10n::t() and L10n::tt()
|
2011-03-19 08:10:05 -04:00
|
|
|
functions, and creates a util/messages.po file.
|
2011-03-28 19:10:12 -04:00
|
|
|
|
2016-09-30 10:46:56 -04:00
|
|
|
$ cd util; ./run_xgettext.sh
|
2011-03-28 19:10:12 -04:00
|
|
|
|
2016-09-30 10:46:56 -04:00
|
|
|
2. copy util/messages.po to view/lang/<language>/messages.po
|
|
|
|
Replace <language> with the language you are working on - e.g. 'es', 'fr', 'de', etc.
|
2015-01-08 07:59:42 -05:00
|
|
|
|
2016-09-30 10:46:56 -04:00
|
|
|
3. open view/lang/<language>/messages.po with a text editor and fill in infos in
|
2011-03-18 07:36:34 -04:00
|
|
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>"
|
|
|
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
|
|
|
"Language: \n"
|
|
|
|
|
|
|
|
(eg:
|
|
|
|
"Last-Translator: Guybrush Threepwood <gb@host.com>"
|
|
|
|
"Language-Team: Pirate Friendika <pirate-friendika-ml@host.com>\n"
|
|
|
|
"Language: pi\n"
|
|
|
|
)
|
2016-09-30 10:46:56 -04:00
|
|
|
|
2011-03-18 07:36:34 -04:00
|
|
|
For the line
|
|
|
|
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
2016-09-30 10:46:56 -04:00
|
|
|
read GNU gettext manual at
|
2011-03-18 07:36:34 -04:00
|
|
|
http://www.gnu.org/software/hello/manual/gettext/Plural-forms.html
|
2016-09-30 10:46:56 -04:00
|
|
|
|
2011-03-18 07:36:34 -04:00
|
|
|
4. You could then translate the strings in text editor, but I suggest to use one
|
|
|
|
of the many .po editors out there, like QtLinguist
|
2016-09-30 10:46:56 -04:00
|
|
|
|
|
|
|
5. run
|
2018-03-18 23:47:38 -04:00
|
|
|
$ php bin/console po2php view/lang/<language>/messages.po
|
2011-03-18 07:36:34 -04:00
|
|
|
to create the strings.php file
|
2016-09-30 10:46:56 -04:00
|
|
|
|
2011-03-18 07:36:34 -04:00
|
|
|
When strings are added or modified in source, you could run
|
2016-09-30 10:46:56 -04:00
|
|
|
$ cd util; ./run_xgettext.sh ../view/lang/<language>/messages.po
|
2011-03-30 10:46:22 -04:00
|
|
|
to extract strings from source files and join them with the existing .po file:
|
2011-03-18 07:36:34 -04:00
|
|
|
new strings are added, the existing are not overwritten.
|
2016-09-30 10:46:56 -04:00
|
|
|
|
2012-02-19 14:12:49 -05:00
|
|
|
If you already translated Friendica using strings.php, you could import your old
|
2011-03-18 07:36:34 -04:00
|
|
|
translation to messages.po. Run:
|
2018-03-18 23:44:27 -04:00
|
|
|
$ php bin/console php2po view/lang/<language>/strings.php
|