Tech talk 10/7/14
Pavel Bosin
"i18n or Internationalization
is the process of designing a software application so that it can potentially be adapted to various languages and regions without engineering changes."
wikipedia
L10n or Localization
is the process of of adapting internationalized software for a specific region or language by adding locale-specific components and translating text."
wikipedia
Localization (which is potentially performed multiple times, for different locales) uses the infrastructure or flexibility provided by internationalization (which is ideally performed only once, or as an integral part of ongoing development).
The terms are frequently abbreviated to the numeronyms i18n (where 18 stands for the number of letters between the first i and last n in internationalization) and L10n respectively, due to the length of the words.
e.g. C5s.com
CLDR languages


<p>Welcome, {{ username }}</p>
In spanish, one for each gender:
<p>Bienvenido, {{ username }}</p>
<p>Bienvenida, {{ username }}</p>
Capitalization, upper- and lower-casing


Description Number of Offers Value
Savings 3 15
Specials 2 22
Description Number of Value
Savings Offers 15
Specials 3 22
2
var date = new Date(); date.toLocaleDateString();
There are some unreliable hacks, like querying navigator.language in Chrome and Firefox, or navigator.browser Language in IE, or looking at the HTTP Accept-Language header using XHR.
So, just ask if you need to. Or provide a way for the user to select their locale preferences.
Django has full support for translation of text, formatting of dates, times and numbers, and time zones.
Essentially, Django does two things:
Text translation in Django python code
from django.utils.translation import ugettext as _
from django.http import HttpResponse
def my_greeting():
greeting = _("Welcome to the site.")
str = _('Today is %(month)s %(day)s.') % {'month': m, 'day': d}
Pluralization in Django python code
from django.utils.translation import ungettext
def hello_world(request, count):
page = ungettext(
'there is %(count)d object',
'there are %(count)d objects',
count) % {
'count': count,
}
Use lazy translation
... ungettext_lazy()
Text translation in Django templates
<title>{% trans "This is the title." %}</title>
<title>{% trans myvar %}</title>
{% trans "This is the title" as the_title %}
<title>{{ the_title }}</title>
<meta name="description" content="{{ the_title }}">
{% blocktrans %}This string will have {{ value }} inside.{% endblocktrans %}
{% blocktrans with amount=article.savings %}
Your savings value is $ {{ amount }}.
{% endblocktrans %}
{% blocktrans with amount=article.price count years=i.length %}
That will cost $ {{ amount }} per year.
{% plural %}
That will cost $ {{ amount }} per {{ years }} years.
{% endblocktrans %}
Add i18n to url patterns (urls.py)
js_info_dict = { 'domain': 'djangojs', 'packages': ('paiweb',), } urlpatterns = patterns('', (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict), )
Include i18n file in html template
<script src="{% url "django.views.i18n.javascript_catalog" %}"></script>
Use gettext(), ngettext(), in JavaScript code
document.write(gettext('this is to be translated'));
var object_cnt = 1 // or 0, or 2, or 3, ...
s = ngettext('literal for the singular case',
'literal for the plural case', object_cnt);
fmts = ngettext('There is %s object. Remaining: %s',
'There are %s objects. Remaining: %s', 11);
s = interpolate(fmts, [11, 20]);
// s is 'There are 11 objects. Remaining: 20'
It provides localization rules for various Angular components.
It works well for number systems, formatting, grouping and precision as well as decimal marks.
It also does datetime, currency formatting.
Used through the built-in angular filters.
Edition 1 provides most of the services that are similar to $locale along with most notably, Collation, in two scenarios: sorting a set of strings and searching within a set of strings. Collation is parameterized by locale and aware of Unicode.
Intl object Currently supported in IE11, Chrome and Firefox Nightly Builds controlled via a flag. Compatibility Table
Upcoming edition 2 will support some more common use-cases like message formatting: format a string with placeholders, including plural and gender support. However, it will be based on Es6 and will not be backwards compatible anymore.
angular-translate uses ICU's MessageFormat which uses a different kind of "interpolation", e.g. it uses single curly braces instead of double curly braces, which means one misses all features angular built-in interpolation brings (filters etc).
angular-gettext is too much magic, not enough control in the hands of the app developer. also, it bypasses certain useful angularjs functionality like the ngPluralize directive.
by Rahul Doshi
Community
Example:
Account Settings [!!! Àççôûñţ Šéţţîñĝš !!!]
Pseudo-translation.
There are utilities for this.
Example: “Bad Command” can be translated in Japanese as [JA XXXXX Bad Command XXXXXX JA].
Testing L10n is mostly manual.
By person fluent in the given language.
White box testing:
Starts with looking for all strings in the code at all levels
These slides are available at
http://slides.com/pbosin/g11n/