Internationalization and Localization

Download Report

Transcript Internationalization and Localization

Internationalization and Localization
William Cohen
NCSU CSC 591W
April 9, 2008
This document is licensed under the Attribution-ShareAlike 3.0 United States
license, available at http://creativecommons.org/licenses/by-sa/3.0/us/.
April 9, 2008
1
Outline
●
●
●
Internationalization
Localization
Simple example
April 9, 2008
2
Internationalization
●
●
●
●
●
Often abbreviated as i18n
Refers to making the program code portable between languages
Allows program to work in multiple languages
Allows changes:
● Time conventions
● Number conventions
● Currency conventions
● Strings
Performed by the programmer
April 9, 2008
3
Localization
●
●
●
●
Often abbreviated as L10N
The actual process of adapting program for local conditions
Implemented by people fluent in the local language
May be implement by non-programmers
April 9, 2008
4
Example Program
#include <libintl.h>
●
#include <locale.h>
●
#include <stdio.h>
●
#include <stdlib.h>
●
int main(void)
●
{
●
setlocale( LC_ALL, "" );
●
bindtextdomain( "hello", "/usr/share/locale" );
●
textdomain( "hello" );
●
printf( gettext( "Hello, world!\n" ) );
●
exit(0);
●
}
April 9, 2008
5
Generating Translation Template
●
●
●
The strings in the program can be translated into many languages
Have a file generated to use as starting point for translators
Generate file with:
● xgettext -d hello -s -o hello.pot hello.c
April 9, 2008
6
Creating Translations
●
●
●
●
Create the file actual file:
● msginit -l es -o es.po -i hello.pot
Then edit the file to add the translated text
Editor will need to support the language being used
Emacs has special mode for working on translation files
April 9, 2008
7
Translation File
●
Have text like the following in file:
#: hello.c:10
#, c-format
msgid "Hello, world!\n"
msgstr "halo, mundo!\n"
April 9, 2008
8
Compiling Translations
●
Convert the human-readable file into machine-usable file:
msgfmt -c -v -o hello.mo es.po
April 9, 2008
9
Installing Translations
●
●
Translations are grouped by locale
Need to put translations into proper place
install hello.mo \
/usr/share/locale/es_ES/LC_MESSAGES
April 9, 2008
10
10
Using the translations
●
Using translations is done by setting environment variable
export LANG=es_ES
April 9, 2008
11
11
Updating Translations
●
●
●
●
●
Programs evolve over time
The text in the program may change over time
Want to minimize work for translators
● Keep the existing translations where possible
● Flag new and changed text
Save xgettext output in new file
Use merge message catalog and template command:
msgmerge -s -U es.po hello-new.pot
April 9, 2008
12
12
Shorthand
●
Reduce the amount of text in code:
#define _(x) gettext(x)
April 9, 2008
13
13
Dealing with Static Initializers
●
●
●
May have static initialization
Cannot call function for these
Use gettext_noop() as marker so string is extracted
April 9, 2008
14
14
Further Reading
●
●
●
●
●
●
http://www.linuxjournal.com/article/3023
http://oriya.sarovar.org/docs/gettext_single.html
http://www.gnu.org/software/gettext/manual/
http://fedoraproject.org/wiki/L10N
http://translate.fedoraproject.org/
http://docs.fedoraproject.org/translation-quick-start-guide/
April 9, 2008
15
15