Chapter 10
The other, brute force solution is to simply edit a file with locale-
specific settings for a given locale. The drawback of this approach is
that we need to remember to re-edit files, when upgrading from one
version of AngularJS to another.
Summary
This chapter touched upon internationalization and localization problems specific to
AngularJS applications. We saw that AngularJS provides the ngLocale module with
locale-specific settings for dates, currencies and number formats. Those settings are
derived from the closure library and influence behavior of some of the build-in filters.
The biggest part of localization efforts is often devoted to translating existing partials
and messages embedded in JavaScript code. We've explored various approaches
for making AngularJS partials work with translated data: filters, directives and
the build-time solution. While the filter-based approach sounds like a good idea it
comes with the performance-penalty that might be unacceptable for many projects.
Directive-based approach solves the performance problem, but is not flexible enough
for real-life applications. This is why we've explored a recommended approach to
translating strings in AngularJS partials build-time solution where translation is
done before templates reach a browser.
We've concluded this chapter with number of i18n/i10n related patterns. We've
started off by looking into options for initializing and switching locale. The current
version of AngularJS requires that a locale is selected before the application's startup,
and this is why we've focused on determining and initializing locale on the server-
side, dynamically generating application's landing page. Switching locale on the fly
is not an option with the version of AngularJS published as of time of this writing so
our best call is to redirect users to a landing page to switch locales.
The other patterns described in this chapter dealt with customizing date, number
and currencies format for data display. While AngularJS provides sensible defaults
for locale-specific filters there are times where you might tweak things a little bit. A
decorator around existing filters is a good approach to customize data output.
At this point we should have a fully functional, internationalized AngularJS web
application. The next chapter will focus on making this application robust. More
specifically, we are going to look into identifying and addressing any potential
performance-related issues.