SlideShare a Scribd company logo
Internationalizing
Your Angular
App
Internationalization & Localization Basics
Internationalization
Basics
What is localization?
“Localization refers to the adaptation of a
product, application or document content to
meet the language, cultural and other
requirements of a specific target market (a
locale).”
-- W3C
What is localization? (cont.)
Detecting the user’s locale
Writing text in a way that the user understands based on his
locale, whether through languages, dialects, or idioms
Displaying data in a way that makes sense to the user based
on his locale
This includes: date formats, currency, time formats
Ensuring graphics and design elements communicate the
intended message
Includes colors, symbols, and icons
Also known as l10n
What is internationalization?
“Internationalization is the design and
development of a product, application or
document content that enables easy
localization for target audiences that vary in
culture, region, or language.”
-- W3C
What is internationalization? (cont.)
Building your app with the flexibility of supporting multiple
locales
Multiple languages, currencies, countries, name displays,
address displays, date and time formats
Ability to change the language, whether through browser
detection or allowing the user to choose the language of
display
Offering multiple locales to the user
Determining which character sets to use (Typically Unicode)
Also known as i18n
Methods of supporting i18n and l10n
1.Selecting a region and being redirected to
another page that supports that locale:
a.Subdomains for each locale that serves up different
HTML content
b.Separate websites for each locale
2.JavaScript for showing/hiding or swapping
out content
Detecting the browser’s locale
1. Can use the browser object:
if(navigator.language !== undefined && navigator.language !==
null){
var language = navigator.language;
language = language.toLowerCase();
} else { //Handles IE
var language = navigator.userLanguage;
language = language.toLowerCase();
};
Angular i18n
The $locale service
Angular comes with built in support for many locales. Like many of the
extra Angular services (i.e., ngRoute, ngResource, ngMocks), you’ll
have to install.
bower | npm install angular-i18n
The folder installed will contain locale files for handling the date,
currency, and number filters.
angular.module(‘myI18nApp’, [‘ngLocale’, ‘tmh.dynamicLocale’, ‘pascalprecht.translate’])
Built in filters for i18n
date: Takes a string parameter which translates into a format. (like:
{{dateObj.startDate | date: ‘shortDate’}}
shortDate: In en-us, formats as 09/24/2015
longDate: In en-us, formats as September 24, 2015
fullDate: In en-us, formats as Thursday, September 24, 2015
currency: Appends or prepends the currency symbol based on the current
user’s locale, as well as manages commas and decimals.
Note: Watch out! It only translates the symbol, not the monetary value.
number: When used by itself, it defaults to formatting the number to the
locale’s format. When used in conjunction with the additional parameter
fractionSize, it rounds the number to the number of places specified.
{{product.inStock | number: 3}} will display 1000 as 1,000
Angular
Translate
Angular Translate
Module that aids in i18n and l10n for
language, pluralization, and lazy loading
Can be used as a directive or filter (both in the
DOM and in the controller)
Allows you to move i18n from the server to
the client
Setting up Angular Translate
Plugins:
1. angular-translate: Main plugin; contains the $translate service.
2. angular-translate-loader-static-files: Helper plugin that allows
devs to specify a file name pattern for loading translation files, as
well as the preferred language to fall back on.
3. angular-translate-loader-url: Helper plugin that allows for
async/lazy loading.
4. angular-translate-partial-loader: Helper plugin that allows devs to
load the translation files for only one module.
Setting up Angular Translate (cont.)
Steps:
1. Download the source files
a. Download from Github
b. bower | npm install
2. Include the scripts in your page
3. Inject Angular Translate as a dependency in the module(s) you want translated
angular.module(‘myI18nApp’, [‘ngLocale’, ‘tmh.dynamicLocale’,
‘pascalprecht.translate’])
4. In your app’s configuration, if you’re using the static loader, inject the $translateProvider:
$translateProvider.useStaticFilesLoader({
prefix: '../languages/',
suffix: '.json'
});
Files for Translations
Should be in JSON format
Multiple files for each locale
i.e., en-gb.json for the UK, en-us for the US, es-es for Spain, es-mx for Mexico, etc etc
Each file should be stored in a common folder, i.e., ‘locale’ or ‘languages’
Can name properties with a single word, or as ‘dot notation’ to designate sections:
{
"navigation.dashboard": "Dashboard",
"navigation.appointments": "Appointments",
"navigation.addAppt": "Add New Appointment",
"navigation.addOneTimeAppt": "Add One Time Appointment",
"navigation.addRepeatingAppt": "Add Repeating Appointments",
"navigation.addTimeOff": "Add New Time Off",
....
}
Inserting translations in your text
Can be done several ways:
1. The translate filter
<button>{{‘btn.close’ | translate}}</button>
1. The translate directive
<button>
<span translate=“btn.close”>Close</span>
</button>
1. Using the translate filter in the controller
$translate('Home.calendar')
.then(function(translatedValue){
$scope.mainTitle = translatedValue;
})
Passing parameters to translated strings
1. HTML:
<div>
<span translate=“Calendar.title” translate-values=“{‘date’:
calendar.defaultDate}”>Today’s date is {{calendar.defaultDate}}</span>
</div>
2. Interpolations of the variable in JSON:
“Calendar.title”: “Today’s date is {{date}}”
Compiling translations with HTML
There are cases where you can’t break a line for HTML changes (links, emphasis, etc) and
keep it syntactically correct for all languages.
HTML:
<span translate= “Text.withLink” translate-compile>
To learn more, <a href=“#”>view our documentation</a>.
</span>
JSON:
“Text.withLink”: “To learn more, <a href=‘#’>view our documentation.”
Making Locale
Dynamic
Angular Dynamic Locale
Allows users to choose and change their locale
Allows developers to pass in the browser’s locale (or
stored locale) and change it from the default locale if
necessary
Changes the locale at app’s runtime, which allows you
to use a stored locale
Modifies the $locale object so changing the locale will
change all objects relying on the $locale service
Using Angular Dynamic Locale
1. Install with bower | npm install angular-dynamic-locale
2. Inject into your module: angular.module(‘myI18nApp’, [‘ngLocale’, ‘tmh.dynamicLocale’])
3. In your app’s configuration, do:
app.config(["tmhDynamicLocaleProvider", function(tmhDynamicLocaleProvider){
tmhDynamicLocaleProvider.localeLocationPattern(
'../bower_components/angular-i18n/angular-locale_{{locale}}.js'
);
tmhDynamicLocaleProvider.defaultLocale(language);
//Default language
if(language === 'es' || language === 'fr'){ //using this format so it won't try to pull in files that
don't exist, like es-mx
$translateProvider.use(language);
} else {
$translateProvider.preferredLanguage('en-us');
};
}]);
Handling Calendars -- Angular UI Bootstrap
Datepicker
Angular UI Bootstrap Datepicker: Built on top of the date filter so everything is localized.
Settings include:
starting-day
Adjustments through the controller, passed into the directive’s helper attributes
HTML:
...
<input type="text" class="form-control" datepicker-popup="shortDate" ng-model="dateObj.startDate" is-
open="datepickers.start" datepicker-options="{{dateOptions}}" date-disabled="disabled(date, mode)" close-
text="Close" ng-click="openDT($event, 'start')" />
…
JS:
var firstDayOfWeek = $window.sessionStorage.getItem(‘firstDayOfWeek’);
$scope.dateOptions = {
'starting-day': firstDayOfWeek
};
Handling Calendars -- Angular UI Calendar
Angular wrapper for fullCalendar. Has settings which include:
dayNames
dayNamesShort
monthNames
monthNamesShort
lang
firstDay
timeFormat
To adjust for i18n, in your HTML you need:
<div ui-calendar="uiConfig.calendar" config="uiConfig.calendar" calendar="myCalendar" class="calendar"
ng-model="eventSources"></div>
And in your controller:
var firstDayOfWeek = $window.sessionStorage.getItem(‘firstDayOfWeek’);
$scope.uiConfig = {
calendar:{
lang: currentLang,
firstDay: firstDayOfWeek,
Triggering
Locale Changes
on the Fly
Triggering locale change on directives
1. Use the $provide service and pass in the name of the directive to get the registered “map”
for that directive
a. Providers expose the directive’s API app-wide and registers them with the injectors
b. Using the decorator method, we can intercept the creation of the directive on load.
2. Catches the $delegate (the original directive’s “map”, which can then be overwritten or
monkey patched)
3. Set up listener on the directive’s scope on $localeChangeSuccess (this requires Angular
Dynamic Locale)
4. Make modifications as needed (i.e., changing the first day of the week property on a
calendar object)
5. Refresh the scope/alert the scope to the changes
a. Call a method in the directive link (i.e., scope.move() )
b. Use apply() to call the directive link with the modified scope and parameters:
originalLink.apply(this, arguments)
Triggering locale change on directives
$provide.decorator('daterangeDirective', function($delegate, $compile, $parse, $translate, $rootScope) {
angular.forEach($delegate, function (directive) {
var originalCompile = directive.compile;
var originalLink = directive.link;
if (originalCompile) {
directive.compile = function () {
return function ($scope, $element, $attributes, ngModel) {
$scope.$on('$localeChangeSuccess', function () {
directive.link($scope, $element, $attributes, ngModel, $compile, $parse, $translate, $rootScope); //have to run
the main fn on the directive b/c it will apply all the changes
});
originalLink.apply(this, arguments);
};
}
}
});
return $delegate;
});
Triggering locale change on Angular UI Calendar
$provide.decorator('uiCalendarDirective', function($delegate, $locale, $rootScope, uiCalendarConfig) {
…
directive.compile = function () {
return function (scope, elm, attrs, controller) {
scope.$on('$localeChangeSuccess', function () {
uiCalendarConfig.dayNames = $locale.DATETIME_FORMATS.DAY;
uiCalendarConfig.dayNamesShort = $locale.DATETIME_FORMATS.SHORTDAY;
uiCalendarConfig.monthNames = $locale.DATETIME_FORMATS.MONTH;
uiCalendarConfig.monthNamesShort = $locale.DATETIME_FORMATS.SHORTMONTH;
uiCalendarConfig.lang = currentLang;
});
originalLink.apply(this, arguments); //This triggers the calendar to update on language change
};
}
}
…
});
Storing Locale
Methods of Storing Locale
1. Session Storage: For temporary storage/only
detecting browser storage.
2. Local Storage: For semi-permanent storage/only
detecting browser storage.
3. Server Side: For permanent storage/when user
wants to see the app in his locale regardless of
computer/browser used to signed in.
Changing language
HTML: <li><a href ng-click="changeLanguage('en-us', 0, account)" class="flag flag-us"></a></li>
JS: $scope.changeLanguage = function(language, firstDayOfWeek, account){
account.locale = language;
account.firstDayOfWeek = firstDayOfWeek;
$translate.use(language);
tmhDynamicLocale.set(language);
$rootScope.$broadcast('firstDayOfWeekUpdated');
//Change language on server by updating the user account
accountData.updateAccount(accountId, account).then(function(data){
//Success ...
}, function(data){
//Error ...
})
};
Setting from Saved Locale
To set the app to the locale saved on the server or sessionStorage, in controller:
//Fetch data from the server/sessionStorage first
//Will default to English, thanks to the setup in app.config
if($scope.account.locale !== null){
tmhDynamicLocale.set($scope.account.locale.toLowerCase());
$translate.use($scope.account.locale.toLowerCase());
};
Wrapping Up
Food for Thought
Start implementing i18n and l10n support early in development
As you build new pages, add translations
Determine your app’s target markets/locales with business rules
Map out components and features that will need localization (I.e.,
calendars, date range pickers, timepickers, etc)
Ask yourself how automated you want l10n to be -- i.e., browser
detection, users choosing which locale, etc
Q&A
Questions? Comments? Fire away!
Resources
Links:
Angular i18n guide: https://docs.angularjs.org/guide/i18n
Angular Translate: https://angular-translate.github.io/
Angular Dynamic Locale: http://lgalfaso.github.io/angular-dynamic-locale/
W3C International: http://www.w3.org/International/
Scotch IO Tutorial: https://scotch.io/tutorials/internationalization-of-angularjs-applications
Reach out to me:
email: sarah@sarah-hudson.com
Twitter: @SarahHudson2008

More Related Content

What's hot

Event handling
Event handlingEvent handling
Event handling
swapnac12
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
Shailendra Chauhan
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
Rishi Kothari
 
Chapter 2 Java Methods
Chapter 2 Java MethodsChapter 2 Java Methods
Chapter 2 Java Methods
Khirulnizam Abd Rahman
 
JAVA PROGRAMMING
JAVA PROGRAMMING JAVA PROGRAMMING
JAVA PROGRAMMING
Niyitegekabilly
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
1 Introduction To Java Technology
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology
dM Technologies
 
XSLT
XSLTXSLT
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
Prawesh Shrestha
 
Javascript
JavascriptJavascript
Javascript
JavascriptJavascript
Javascript
mussawir20
 
Constants in java
Constants in javaConstants in java
Constants in java
Manojkumar C
 
Android Networking
Android NetworkingAndroid Networking
Android Networking
Maksym Davydov
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
Krazy Koder
 
JAVA PPT by NAVEEN TOKAS
JAVA PPT by NAVEEN TOKASJAVA PPT by NAVEEN TOKAS
JAVA PPT by NAVEEN TOKAS
NAVEEN TOKAS
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
Jaya Kumari
 
Bootstrap ppt
Bootstrap pptBootstrap ppt
Bootstrap ppt
Nidhi mishra
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
Elizabeth Thomas
 
The principles of volunteering, internship, networking, and skill acquisition...
The principles of volunteering, internship, networking, and skill acquisition...The principles of volunteering, internship, networking, and skill acquisition...
The principles of volunteering, internship, networking, and skill acquisition...
MgbechidinmaChiamaka
 
Android Components & Manifest
Android Components & ManifestAndroid Components & Manifest
Android Components & Manifest
ma-polimi
 

What's hot (20)

Event handling
Event handlingEvent handling
Event handling
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
Chapter 2 Java Methods
Chapter 2 Java MethodsChapter 2 Java Methods
Chapter 2 Java Methods
 
JAVA PROGRAMMING
JAVA PROGRAMMING JAVA PROGRAMMING
JAVA PROGRAMMING
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
1 Introduction To Java Technology
1 Introduction To Java Technology 1 Introduction To Java Technology
1 Introduction To Java Technology
 
XSLT
XSLTXSLT
XSLT
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Javascript
JavascriptJavascript
Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Constants in java
Constants in javaConstants in java
Constants in java
 
Android Networking
Android NetworkingAndroid Networking
Android Networking
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
 
JAVA PPT by NAVEEN TOKAS
JAVA PPT by NAVEEN TOKASJAVA PPT by NAVEEN TOKAS
JAVA PPT by NAVEEN TOKAS
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
 
Bootstrap ppt
Bootstrap pptBootstrap ppt
Bootstrap ppt
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
 
The principles of volunteering, internship, networking, and skill acquisition...
The principles of volunteering, internship, networking, and skill acquisition...The principles of volunteering, internship, networking, and skill acquisition...
The principles of volunteering, internship, networking, and skill acquisition...
 
Android Components & Manifest
Android Components & ManifestAndroid Components & Manifest
Android Components & Manifest
 

Similar to Internationalizing Your AngularJS App

Create Location Sharing apps using the Ionic framework
Create Location Sharing apps using the Ionic framework					Create Location Sharing apps using the Ionic framework
Create Location Sharing apps using the Ionic framework
Shelly Megan
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
Nitin Giri
 
Start your journey with angular | Basic Angular
Start your journey with angular | Basic AngularStart your journey with angular | Basic Angular
Start your journey with angular | Basic Angular
Anwarul Islam
 
Internationalize your JavaScript Application: Prepare for "the next billion" ...
Internationalize your JavaScript Application: Prepare for "the next billion" ...Internationalize your JavaScript Application: Prepare for "the next billion" ...
Internationalize your JavaScript Application: Prepare for "the next billion" ...
Kevin Hakanson
 
Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014
Sarah Hudson
 
I18n
I18nI18n
I18n
soon
 
Developing a Demo Application with Angular 4 - J2I
Developing a Demo Application with Angular 4 - J2IDeveloping a Demo Application with Angular 4 - J2I
Developing a Demo Application with Angular 4 - J2I
Nader Debbabi
 
An Overview of Angular 4
An Overview of Angular 4 An Overview of Angular 4
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
Ravi Mone
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
Aishura Aishu
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
Naveen Pete
 
Using Sakai with Multiple Locales
Using Sakai with Multiple LocalesUsing Sakai with Multiple Locales
Using Sakai with Multiple Locales
ballsy333
 
Angular js firebase-preso
Angular js firebase-presoAngular js firebase-preso
Angular js firebase-preso
Avinash Kondagunta
 
BarCamp KL H20 Open Social Hackathon
BarCamp KL H20 Open Social HackathonBarCamp KL H20 Open Social Hackathon
BarCamp KL H20 Open Social Hackathon
marvin337
 
Micronaut Launchpad
Micronaut LaunchpadMicronaut Launchpad
Micronaut Launchpad
Zachary Klein
 
A Guide to Using Navigator in React Native for Turkish Businesses
A Guide to Using Navigator in React Native for Turkish BusinessesA Guide to Using Navigator in React Native for Turkish Businesses
A Guide to Using Navigator in React Native for Turkish Businesses
Shiv Technolabs Pvt. Ltd.
 
Marrying together the worlds of ADF and HTML5 & AngularJS - Oracle OpenWorld ...
Marrying together the worlds of ADF and HTML5 & AngularJS - Oracle OpenWorld ...Marrying together the worlds of ADF and HTML5 & AngularJS - Oracle OpenWorld ...
Marrying together the worlds of ADF and HTML5 & AngularJS - Oracle OpenWorld ...
Getting value from IoT, Integration and Data Analytics
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
SaleemMalik52
 
Angular js workshop
Angular js workshopAngular js workshop
Angular js workshop
Rolands Krumbergs
 
pebble - Building apps on pebble
pebble - Building apps on pebblepebble - Building apps on pebble
pebble - Building apps on pebble
Aniruddha Chakrabarti
 

Similar to Internationalizing Your AngularJS App (20)

Create Location Sharing apps using the Ionic framework
Create Location Sharing apps using the Ionic framework					Create Location Sharing apps using the Ionic framework
Create Location Sharing apps using the Ionic framework
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
 
Start your journey with angular | Basic Angular
Start your journey with angular | Basic AngularStart your journey with angular | Basic Angular
Start your journey with angular | Basic Angular
 
Internationalize your JavaScript Application: Prepare for "the next billion" ...
Internationalize your JavaScript Application: Prepare for "the next billion" ...Internationalize your JavaScript Application: Prepare for "the next billion" ...
Internationalize your JavaScript Application: Prepare for "the next billion" ...
 
Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014
 
I18n
I18nI18n
I18n
 
Developing a Demo Application with Angular 4 - J2I
Developing a Demo Application with Angular 4 - J2IDeveloping a Demo Application with Angular 4 - J2I
Developing a Demo Application with Angular 4 - J2I
 
An Overview of Angular 4
An Overview of Angular 4 An Overview of Angular 4
An Overview of Angular 4
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Using Sakai with Multiple Locales
Using Sakai with Multiple LocalesUsing Sakai with Multiple Locales
Using Sakai with Multiple Locales
 
Angular js firebase-preso
Angular js firebase-presoAngular js firebase-preso
Angular js firebase-preso
 
BarCamp KL H20 Open Social Hackathon
BarCamp KL H20 Open Social HackathonBarCamp KL H20 Open Social Hackathon
BarCamp KL H20 Open Social Hackathon
 
Micronaut Launchpad
Micronaut LaunchpadMicronaut Launchpad
Micronaut Launchpad
 
A Guide to Using Navigator in React Native for Turkish Businesses
A Guide to Using Navigator in React Native for Turkish BusinessesA Guide to Using Navigator in React Native for Turkish Businesses
A Guide to Using Navigator in React Native for Turkish Businesses
 
Marrying together the worlds of ADF and HTML5 & AngularJS - Oracle OpenWorld ...
Marrying together the worlds of ADF and HTML5 & AngularJS - Oracle OpenWorld ...Marrying together the worlds of ADF and HTML5 & AngularJS - Oracle OpenWorld ...
Marrying together the worlds of ADF and HTML5 & AngularJS - Oracle OpenWorld ...
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
 
Angular js workshop
Angular js workshopAngular js workshop
Angular js workshop
 
pebble - Building apps on pebble
pebble - Building apps on pebblepebble - Building apps on pebble
pebble - Building apps on pebble
 

Recently uploaded

UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
kalichargn70th171
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
kgyxske
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
Reetu63
 

Recently uploaded (20)

UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
 

Internationalizing Your AngularJS App

  • 3. What is localization? “Localization refers to the adaptation of a product, application or document content to meet the language, cultural and other requirements of a specific target market (a locale).” -- W3C
  • 4. What is localization? (cont.) Detecting the user’s locale Writing text in a way that the user understands based on his locale, whether through languages, dialects, or idioms Displaying data in a way that makes sense to the user based on his locale This includes: date formats, currency, time formats Ensuring graphics and design elements communicate the intended message Includes colors, symbols, and icons Also known as l10n
  • 5. What is internationalization? “Internationalization is the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language.” -- W3C
  • 6. What is internationalization? (cont.) Building your app with the flexibility of supporting multiple locales Multiple languages, currencies, countries, name displays, address displays, date and time formats Ability to change the language, whether through browser detection or allowing the user to choose the language of display Offering multiple locales to the user Determining which character sets to use (Typically Unicode) Also known as i18n
  • 7. Methods of supporting i18n and l10n 1.Selecting a region and being redirected to another page that supports that locale: a.Subdomains for each locale that serves up different HTML content b.Separate websites for each locale 2.JavaScript for showing/hiding or swapping out content
  • 8. Detecting the browser’s locale 1. Can use the browser object: if(navigator.language !== undefined && navigator.language !== null){ var language = navigator.language; language = language.toLowerCase(); } else { //Handles IE var language = navigator.userLanguage; language = language.toLowerCase(); };
  • 10. The $locale service Angular comes with built in support for many locales. Like many of the extra Angular services (i.e., ngRoute, ngResource, ngMocks), you’ll have to install. bower | npm install angular-i18n The folder installed will contain locale files for handling the date, currency, and number filters. angular.module(‘myI18nApp’, [‘ngLocale’, ‘tmh.dynamicLocale’, ‘pascalprecht.translate’])
  • 11. Built in filters for i18n date: Takes a string parameter which translates into a format. (like: {{dateObj.startDate | date: ‘shortDate’}} shortDate: In en-us, formats as 09/24/2015 longDate: In en-us, formats as September 24, 2015 fullDate: In en-us, formats as Thursday, September 24, 2015 currency: Appends or prepends the currency symbol based on the current user’s locale, as well as manages commas and decimals. Note: Watch out! It only translates the symbol, not the monetary value. number: When used by itself, it defaults to formatting the number to the locale’s format. When used in conjunction with the additional parameter fractionSize, it rounds the number to the number of places specified. {{product.inStock | number: 3}} will display 1000 as 1,000
  • 13. Angular Translate Module that aids in i18n and l10n for language, pluralization, and lazy loading Can be used as a directive or filter (both in the DOM and in the controller) Allows you to move i18n from the server to the client
  • 14. Setting up Angular Translate Plugins: 1. angular-translate: Main plugin; contains the $translate service. 2. angular-translate-loader-static-files: Helper plugin that allows devs to specify a file name pattern for loading translation files, as well as the preferred language to fall back on. 3. angular-translate-loader-url: Helper plugin that allows for async/lazy loading. 4. angular-translate-partial-loader: Helper plugin that allows devs to load the translation files for only one module.
  • 15. Setting up Angular Translate (cont.) Steps: 1. Download the source files a. Download from Github b. bower | npm install 2. Include the scripts in your page 3. Inject Angular Translate as a dependency in the module(s) you want translated angular.module(‘myI18nApp’, [‘ngLocale’, ‘tmh.dynamicLocale’, ‘pascalprecht.translate’]) 4. In your app’s configuration, if you’re using the static loader, inject the $translateProvider: $translateProvider.useStaticFilesLoader({ prefix: '../languages/', suffix: '.json' });
  • 16. Files for Translations Should be in JSON format Multiple files for each locale i.e., en-gb.json for the UK, en-us for the US, es-es for Spain, es-mx for Mexico, etc etc Each file should be stored in a common folder, i.e., ‘locale’ or ‘languages’ Can name properties with a single word, or as ‘dot notation’ to designate sections: { "navigation.dashboard": "Dashboard", "navigation.appointments": "Appointments", "navigation.addAppt": "Add New Appointment", "navigation.addOneTimeAppt": "Add One Time Appointment", "navigation.addRepeatingAppt": "Add Repeating Appointments", "navigation.addTimeOff": "Add New Time Off", .... }
  • 17. Inserting translations in your text Can be done several ways: 1. The translate filter <button>{{‘btn.close’ | translate}}</button> 1. The translate directive <button> <span translate=“btn.close”>Close</span> </button> 1. Using the translate filter in the controller $translate('Home.calendar') .then(function(translatedValue){ $scope.mainTitle = translatedValue; })
  • 18. Passing parameters to translated strings 1. HTML: <div> <span translate=“Calendar.title” translate-values=“{‘date’: calendar.defaultDate}”>Today’s date is {{calendar.defaultDate}}</span> </div> 2. Interpolations of the variable in JSON: “Calendar.title”: “Today’s date is {{date}}”
  • 19. Compiling translations with HTML There are cases where you can’t break a line for HTML changes (links, emphasis, etc) and keep it syntactically correct for all languages. HTML: <span translate= “Text.withLink” translate-compile> To learn more, <a href=“#”>view our documentation</a>. </span> JSON: “Text.withLink”: “To learn more, <a href=‘#’>view our documentation.”
  • 21. Angular Dynamic Locale Allows users to choose and change their locale Allows developers to pass in the browser’s locale (or stored locale) and change it from the default locale if necessary Changes the locale at app’s runtime, which allows you to use a stored locale Modifies the $locale object so changing the locale will change all objects relying on the $locale service
  • 22. Using Angular Dynamic Locale 1. Install with bower | npm install angular-dynamic-locale 2. Inject into your module: angular.module(‘myI18nApp’, [‘ngLocale’, ‘tmh.dynamicLocale’]) 3. In your app’s configuration, do: app.config(["tmhDynamicLocaleProvider", function(tmhDynamicLocaleProvider){ tmhDynamicLocaleProvider.localeLocationPattern( '../bower_components/angular-i18n/angular-locale_{{locale}}.js' ); tmhDynamicLocaleProvider.defaultLocale(language); //Default language if(language === 'es' || language === 'fr'){ //using this format so it won't try to pull in files that don't exist, like es-mx $translateProvider.use(language); } else { $translateProvider.preferredLanguage('en-us'); }; }]);
  • 23. Handling Calendars -- Angular UI Bootstrap Datepicker Angular UI Bootstrap Datepicker: Built on top of the date filter so everything is localized. Settings include: starting-day Adjustments through the controller, passed into the directive’s helper attributes HTML: ... <input type="text" class="form-control" datepicker-popup="shortDate" ng-model="dateObj.startDate" is- open="datepickers.start" datepicker-options="{{dateOptions}}" date-disabled="disabled(date, mode)" close- text="Close" ng-click="openDT($event, 'start')" /> … JS: var firstDayOfWeek = $window.sessionStorage.getItem(‘firstDayOfWeek’); $scope.dateOptions = { 'starting-day': firstDayOfWeek };
  • 24. Handling Calendars -- Angular UI Calendar Angular wrapper for fullCalendar. Has settings which include: dayNames dayNamesShort monthNames monthNamesShort lang firstDay timeFormat To adjust for i18n, in your HTML you need: <div ui-calendar="uiConfig.calendar" config="uiConfig.calendar" calendar="myCalendar" class="calendar" ng-model="eventSources"></div> And in your controller: var firstDayOfWeek = $window.sessionStorage.getItem(‘firstDayOfWeek’); $scope.uiConfig = { calendar:{ lang: currentLang, firstDay: firstDayOfWeek,
  • 26. Triggering locale change on directives 1. Use the $provide service and pass in the name of the directive to get the registered “map” for that directive a. Providers expose the directive’s API app-wide and registers them with the injectors b. Using the decorator method, we can intercept the creation of the directive on load. 2. Catches the $delegate (the original directive’s “map”, which can then be overwritten or monkey patched) 3. Set up listener on the directive’s scope on $localeChangeSuccess (this requires Angular Dynamic Locale) 4. Make modifications as needed (i.e., changing the first day of the week property on a calendar object) 5. Refresh the scope/alert the scope to the changes a. Call a method in the directive link (i.e., scope.move() ) b. Use apply() to call the directive link with the modified scope and parameters: originalLink.apply(this, arguments)
  • 27. Triggering locale change on directives $provide.decorator('daterangeDirective', function($delegate, $compile, $parse, $translate, $rootScope) { angular.forEach($delegate, function (directive) { var originalCompile = directive.compile; var originalLink = directive.link; if (originalCompile) { directive.compile = function () { return function ($scope, $element, $attributes, ngModel) { $scope.$on('$localeChangeSuccess', function () { directive.link($scope, $element, $attributes, ngModel, $compile, $parse, $translate, $rootScope); //have to run the main fn on the directive b/c it will apply all the changes }); originalLink.apply(this, arguments); }; } } }); return $delegate; });
  • 28. Triggering locale change on Angular UI Calendar $provide.decorator('uiCalendarDirective', function($delegate, $locale, $rootScope, uiCalendarConfig) { … directive.compile = function () { return function (scope, elm, attrs, controller) { scope.$on('$localeChangeSuccess', function () { uiCalendarConfig.dayNames = $locale.DATETIME_FORMATS.DAY; uiCalendarConfig.dayNamesShort = $locale.DATETIME_FORMATS.SHORTDAY; uiCalendarConfig.monthNames = $locale.DATETIME_FORMATS.MONTH; uiCalendarConfig.monthNamesShort = $locale.DATETIME_FORMATS.SHORTMONTH; uiCalendarConfig.lang = currentLang; }); originalLink.apply(this, arguments); //This triggers the calendar to update on language change }; } } … });
  • 30. Methods of Storing Locale 1. Session Storage: For temporary storage/only detecting browser storage. 2. Local Storage: For semi-permanent storage/only detecting browser storage. 3. Server Side: For permanent storage/when user wants to see the app in his locale regardless of computer/browser used to signed in.
  • 31. Changing language HTML: <li><a href ng-click="changeLanguage('en-us', 0, account)" class="flag flag-us"></a></li> JS: $scope.changeLanguage = function(language, firstDayOfWeek, account){ account.locale = language; account.firstDayOfWeek = firstDayOfWeek; $translate.use(language); tmhDynamicLocale.set(language); $rootScope.$broadcast('firstDayOfWeekUpdated'); //Change language on server by updating the user account accountData.updateAccount(accountId, account).then(function(data){ //Success ... }, function(data){ //Error ... }) };
  • 32. Setting from Saved Locale To set the app to the locale saved on the server or sessionStorage, in controller: //Fetch data from the server/sessionStorage first //Will default to English, thanks to the setup in app.config if($scope.account.locale !== null){ tmhDynamicLocale.set($scope.account.locale.toLowerCase()); $translate.use($scope.account.locale.toLowerCase()); };
  • 34. Food for Thought Start implementing i18n and l10n support early in development As you build new pages, add translations Determine your app’s target markets/locales with business rules Map out components and features that will need localization (I.e., calendars, date range pickers, timepickers, etc) Ask yourself how automated you want l10n to be -- i.e., browser detection, users choosing which locale, etc
  • 36. Resources Links: Angular i18n guide: https://docs.angularjs.org/guide/i18n Angular Translate: https://angular-translate.github.io/ Angular Dynamic Locale: http://lgalfaso.github.io/angular-dynamic-locale/ W3C International: http://www.w3.org/International/ Scotch IO Tutorial: https://scotch.io/tutorials/internationalization-of-angularjs-applications Reach out to me: email: sarah@sarah-hudson.com Twitter: @SarahHudson2008