2013-10-12

Some correction, rewording etc. :)

← Older revision

Revision as of 2013-10-12T16:18:47

Line 134:

Line 134:

 

 

 

==Search and manage .po files==

 

==Search and manage .po files==



There
is
several operations that you can execute directly on your .po files. They are text files and some scripts such as the '''translate toolkit''' can be used to manipulate them.  

+

There
are
several operations that you can execute directly on your .po files. They are text files and some scripts such as the '''translate toolkit''' can be used to manipulate them.  

 

 



Also,
the ''Search'' field on Pootle is not very effective, using the ''grep'' command line
instruction
under Linux will give you much more significant results when you search for a string in multiple files. This part contains a brief description of some scripts and
example
with ''grep'' and ''sed'' commands to help you manipulate your files.

+

As
the ''Search'' field on Pootle is not very effective, using the ''grep'' command line
instructions
under Linux will give you much more significant results when you search for a string in multiple files. This part contains a brief description of some scripts
,
and
examples
with ''grep'' and ''sed'' commands to help you
to
manipulate your files.

 

 

 

You have first to download the files from Pootle and use the ''cd'' command to be in the directory you want to work on (ui or help).  

 

You have first to download the files from Pootle and use the ''cd'' command to be in the directory you want to work on (ui or help).  

 

 

 

===Translate Toolkit===

 

===Translate Toolkit===



Most of the time
,
the Translate Toolkit packages are available for your distro
, in
case it is not
,
or it is an old version, you can get it from here [http://toolkit.translatehouse.org/]. If you
meet
problems installing or using those scripts, do not hesitate to ask for help on the l10n mailing list.

+

Most of the time the Translate Toolkit packages are available for your distro
. In
case it is not or it is an old version, you can get it from here [http://toolkit.translatehouse.org/]. If you
have any
problems installing or using those scripts, do not hesitate to ask for help on the l10n mailing list.

 

 



Several scripts from the Translate Toolkit are implemented in Pootle, like the ''Failing
Cheks
'' which allow you to check
for
your translation. Some, however, may be relevant for you:

+

Several scripts from the Translate Toolkit are implemented in Pootle, like the ''Failing
Checks
''
,
which allow you to check your translation. Some, however, may be relevant for you:



*'''
Poterminology
''' lets you extract a terminology file from the .po/pot files. Before beginning a translation project, it is
of
a great help to have the most important or ambiguous words filled and translated in a glossary. You will be able to upload this file under a Pootle project too. The [http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/poterminology.html syntax and options] are explained on the site.  

+

*'''
poterminology
''' lets you extract a terminology file from the .po/pot files. Before beginning a translation project, it is a great help to have the most important or ambiguous words filled and translated in a glossary. You will be able to upload this file under a Pootle project too. The [http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/poterminology.html syntax and options] are explained on the site.  



*'''
Posegment
''' will help to increase the quality of your TM by segmenting the po files based on sentence level. The [http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/posegment.html syntax and options] can be found on the site.

+

*'''
posegment
''' will help to increase the quality of your TM by segmenting the po files based on sentence level. The [http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/posegment.html syntax and options] can be found on the site.



*'''
Pocompendium
''' let you create one big po file from a directory of po files. This is useful if you have split
files
to distribute to a team
for example
. The [http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/pocompendium.html syntax and options] are explained on the site.

+

*'''
pocompendium
''' let you create one big po file from a directory of po files. This is useful if you
have for example
have split
a large file
to distribute
it
to a team
of translators
. The [http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/pocompendium.html syntax and options] are explained on the site.  



*'''
Posplit
''' let you extract three .po files respectively containing translated strings, untranslated strings and fuzzy strings. The [http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/posplit.html syntax and options] are explained on the site.

+

*'''
posplit
''' let you extract three .po files respectively containing translated strings, untranslated strings and fuzzy strings. The [http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/posplit.html syntax and options] are explained on the site.

 

 

 

===Using ''grep'' to find strings===

 

===Using ''grep'' to find strings===



The ''grep'' command is used under Linux, OS X or Unix-like
system
to search through text files, or
searches
the given file for lines containing a match to the given strings or words. The command will display the line matching the search.  

+

The ''grep'' command is used under Linux, OS X or Unix-like
systems
to search through text files, or
to search
the given file for lines containing a match to the given strings or words. The command will display the line matching the search.  

 

*The simplest syntax is:  

 

*The simplest syntax is:  

 

  grep 'word' filename.po

 

  grep 'word' filename.po

Line 157:

Line 157:

 

:returns

 

:returns

 

  msgid "Browse"

 

  msgid "Browse"



:Here we
tell
the command to find the word ''Browse'' in the helper.po file which is in ''source''
directory which is in
''accessibility'' directory.

+

:Here we
are telling
the
grep
command to find the word ''Browse'' in the helper.po file
,
which is in
the subdirectory
''source''
of the
''accessibility'' directory.

 

 



*This is not very useful, because you have to know the directory where the string is located while LibreOffice has so many
, so
we will add an option that will look recursively into all the directories contained in the main one. This is the '''-r''' option.

+

*This is not very useful, because you have to know the directory where the string is located
,
while LibreOffice has so many
. So
we will add an option that will look recursively into all the directories
,
contained in the main one. This is the '''-r''' option.

 

:The syntax is:

 

:The syntax is:

 

  grep -r 'word' directory

 

  grep -r 'word' directory

Line 169:

Line 169:

 

:this looks easier! the output gives you the path to the string

 

:this looks easier! the output gives you the path to the string

 

 



*To force to ignore the case of the word
,
for example to search
indifferently
for ''Browse, browse or BROWSE'' you will add the '''-i''' option. The syntax is:

+

*To force to ignore the case of the word
(
for example to search
case-insensitive
for ''Browse, browse or BROWSE''
),
you will add the '''-i''' option. The syntax is:

 

  grep -r -i 'word' directory

 

  grep -r -i 'word' directory

 

 

Line 175:

Line 175:

 

:The syntax is:  

 

:The syntax is:  

 

  grep -r -i -n 'word' diretory

 

  grep -r -i -n 'word' diretory



:Let
make
an example on our own directory with all the options we know:

+

:Let
me show you
an example on our own directory with all the options we know:

 

  sophie@sophie:~/libo_ui-fr$ grep -r -i -n 'Browse' accessibility/

 

  sophie@sophie:~/libo_ui-fr$ grep -r -i -n 'Browse' accessibility/

 

:the output is:

 

:the output is:

 

  accessibility/source/helper.po:23:"RID_STR_ACC_NAME_BROWSEBUTTON\n"

 

  accessibility/source/helper.po:23:"RID_STR_ACC_NAME_BROWSEBUTTON\n"

 

  accessibility/source/helper.po:25:msgid "Browse"

 

  accessibility/source/helper.po:25:msgid "Browse"



:You
know which line to edit to change
the
strings
.  

+

:You
can see, that
the
second entry contains the word to translate
.

 

 

 

*If you want your search to match only the string you have entered, you can add the '''-w''' option. For example to search for ''is'' and not retrieve ''this'' or ''his'', etc.

 

*If you want your search to match only the string you have entered, you can add the '''-w''' option. For example to search for ''is'' and not retrieve ''this'' or ''his'', etc.

Line 194:

Line 194:

 

  sw/source/ui/dialog.po:169:msgid "~File name"

 

  sw/source/ui/dialog.po:169:msgid "~File name"

 

  sw/source/ui/index.po:522:msgid "~File"

 

  sw/source/ui/index.po:522:msgid "~File"



:'''Note''': we use ''egrep'' to match a particular regular expression
, the
''e'' is for ''extended grep'' but you can use the '''-E''' option for that
too
: ''grep -E -r -n 'word1|word2' directory/

+

:'''Note''': we use ''egrep'' to match a particular regular expression
. The
''e'' is for ''extended grep'' but you can use the '''-E''' option for that
as well
: ''grep -E -r -n 'word1|word2' directory/

 

 

 

*If you have an escaping character in your search, like an apostrophe (e.g. ''child's book'' in English or ''l'objet'' in French), the simplest way to overcome that is to enclose the word to search with double quotes instead of single ones, like in this example:

 

*If you have an escaping character in your search, like an apostrophe (e.g. ''child's book'' in English or ''l'objet'' in French), the simplest way to overcome that is to enclose the word to search with double quotes instead of single ones, like in this example:

Line 207:

Line 207:

 

 

 

===Using ''sed'' to modify your files===

 

===Using ''sed'' to modify your files===



Like ''grep'', ''sed'' is a powerful command that let you modify the content of your .po files very easily. Sed stands for ''S''tream ''ED''itor. For example, you want to substitute ''Header'' by ''Title'' on a file, the syntax will be:

+

Like ''grep'', ''sed'' is a powerful command that let you modify the content of your .po files very easily. Sed stands for ''S''tream ''ED''itor. For example,
if
you want to substitute ''Header'' by ''Title'' on a file, the syntax will be:

 

  sed 's/Header/Title/g' <file.po

 

  sed 's/Header/Title/g' <file.po

 

* first you have the name of the command ''s'' for ''substitute''

 

* first you have the name of the command ''s'' for ''substitute''

 

* then you have the original word separated by ''/'' delimiters

 

* then you have the original word separated by ''/'' delimiters



*
then
the word to substitute to the original

+

*
after that
the word to substitute to the original



* ''g'' is used for global and will substitute all the occurrences in the
line
,
without
only the first occurrence
is substitute

+

* ''g'' is used for global and will substitute all the occurrences in the
file
,
and not
only the first occurrence
of the searched word

 

* then the file where the substitution takes place

 

* then the file where the substitution takes place

 

* note the presence of the single quotes too.

 

* note the presence of the single quotes too.



Sed
use
regular expressions to manage the instructions, but the syntax will still remain the same as
the
above. We will not detail all the syntax of the lines given bellow, but
it is
quite simple expressions you can use safely on your files.

+

Sed
uses
regular expressions to manage the instructions, but the syntax will still remain the same as above. We will not detail all the syntax of the lines given bellow, but
they are
quite simple expressions you can use safely on your files.

 

 

 

* Remove comments from a file

 

* Remove comments from a file

Line 224:

Line 224:

 

:Enter the following in the sw/source/ui directory:

 

:Enter the following in the sw/source/ui directory:

 

  sophie@sophie:~/libo_ui-fr/sw/source/ui$ sed '/^#\ /d' utlui.po > tt

 

  sophie@sophie:~/libo_ui-fr/sw/source/ui$ sed '/^#\ /d' utlui.po > tt



:that will create
a tt
file
,
in that directory, containing the strings where all the # at the beginning of the line (^) followed by nothing are deleted (
meaning of
''d'' in the syntax).

+

:that will create
the
file
"tt"
in that directory, containing the strings where all the
"
#
"
at the beginning of the line (^) followed by nothing are deleted (
the
''d'' in the syntax).

 

 

 

:To get the ''tt'' file turn into ''utlui.po'' again:

 

:To get the ''tt'' file turn into ''utlui.po'' again:

Line 233:

Line 233:

 

Taking again our first example, you want to work only on a given line, 306 here:

 

Taking again our first example, you want to work only on a given line, 306 here:

 

  sed '306 s/Header/Title/g' <file.po

 

  sed '306 s/Header/Title/g' <file.po



so now you know how to ''grep'' first on the file to find the string and then use the ''sed'' command

+

so now you know how to ''grep'' first on the file to find the string and then use the ''sed'' command
to correct it

 

 

 

* you will find more information [http://www.gnu.org/software/sed/manual/sed.html on the gnu site] about the delimiters, the regular expressions and syntax.

 

* you will find more information [http://www.gnu.org/software/sed/manual/sed.html on the gnu site] about the delimiters, the regular expressions and syntax.

Show more