SlideShare a Scribd company logo
Data Localization and Translation
Data Localization
and
Translation
Yevhen Shyshkin
yshyshkin@orocrm.com
https://github.com/yshyshkin
Data Localization and Translation
Language localisation is the process of
adapting a product that has been previously
translated into different languages to a
specific country or region.
What is language localization?
Data Localization and Translation
Where localization is applied?
- Name formatting
- Address formatting
- Datetime formatting
- Number formatting
- Decimal
- Integer
- Percent
- Currency
Data Localization and Translation
Localization configuration
System > Configuration > Localization
Data Localization and Translation
Localization configuration
$this->get('oro_locale.settings')->getLocale();
$this->get('oro_locale.settings')->getCurrency();
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Model/LocaleSettings.php
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/public/js/locale-
settings.js
Result: en
USD
PHP:
JS: require(['orolocale/js/locale-settings'],
function(localeSettings) {
localeSettings.getLocale();
localeSettings.getCurrency();
});
Twig: {{ oro_locale() }}
{{ oro_currency() }}
Data Localization and Translation
Name formatting
- Names are formatted based on locale
- Name format configuration can be defined in
any bundle’s YAML file
Resources/config/oro/name_format.yml
- Format may contain placeholders for name
prefix, name suffix, first name,
last name and middle name
- Entity must include OroBundle
LocaleBundleModelFullNameInterface
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Model/FullNameInterface.php
Data Localization and Translation
Name formatting
en: %prefix% %first_name% %middle_name% %last_name% %suffix%
en_US: %prefix% %first_name% %middle_name% %last_name% %suffix%
ru: %last_name% %first_name% %middle_name%
ru_RU: %last_name% %first_name% %middle_name%
Configuration example
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/config/oro/na
me_format.yml
Data Localization and Translation
Name formatting
$user = new User(); // implements FullNameInterface
$user->setNamePrefix('Mr.')
->setFirstName('John')
->setMiddleName('S.')
->setLastName('Doe')
->setNameSuffix('Jr.');
$this->get('oro_locale.formatter.name')->format($user);
$this->get('oro_locale.formatter.name')->format($user, 'ru');
PHP:
Twig: {{ entity|oro_format_name }}
{{ entity|oro_format_name('ru') }}
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Formatter/NameFormatter.php
Data Localization and Translation
Name formatting
require(['orolocale/js/formatter/name'],
function(nameFormatter) {
var user = {
'prefix': 'Mr.',
'first_name': 'John',
'middle_name': 'S.',
'last_name': 'Doe',
'suffix': 'Jr'
};
nameFormatter.format(user);
nameFormatter.format(user, 'ru');
});
JS:
Result: Mr. John S. Doe Jr.
Doe John S.
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/public/js/formatter/na
me.js
Data Localization and Translation
Address formatting
- Addresses are formatted based on primary
location or country address
- Address format configuration can be defined in
any bundle’s YAML file
Resources/config/oro/address_format.yml
- Format may contain placeholders for name,
organization, street, city, region, region code,
country, country code and postal code
- Entity must include OroBundle
LocaleBundleModelAddressInterface
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Model/AddressInterface.php
Data Localization and Translation
Address formatting
US:
format: '%name%n%organization%n%street%n%CITY% %REGION_CODE%
%COUNTRY_ISO2% %postal_code%'
require: [street, city, region, postal_code]
zip_name_type: zip
region_name_type: region
RU:
format: '%postal_code% %COUNTRY%
%CITY%n%STREET%n%organization%n%name%'
require: [street, city, postal_code]
Configuration example
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/config/oro/ad
dress_format.yml
Data Localization and Translation
Address formatting
$country = new Country('US');
$country->setName('United States of America')
->setIso3Code('USA');
$region = new Region('US-CA');
$region->setCode('CA')
->setName('California');
$address = new Address(); // implements AddressInterface
$address->setNamePrefix('Mr.')
->setFirstName('John')
->setMiddleName('S.')
->setLastName('Doe')
->setNameSuffix('Jr.');
$address->setStreet('Random str., 3, 14')
->setCity('Los Angeles')
->setRegion($region)
->setCountry($country)
->setPostalCode('12345')
->setOrganization('Oro Inc.');
$this->get('oro_locale.formatter.address')->format($address);
PHP:
Data Localization and Translation
Address formatting
Twig: {{ address|oro_format_address|nl2br }}
require(['orolocale/js/formatter/address'],
function(addressFormatter) {
var address = {
'prefix': 'Mr.',
'first_name': 'John',
'middle_name': 'S.',
'last_name': 'Doe',
'suffix': 'Jr',
'organization': 'Oro Inc.',
'street': 'Random str., 3, 14',
'city': 'Los Angeles',
'region_code': 'CA',
'country_iso2': 'US',
'postal_code': '12345'
};
addressFormatter.format(address);
});
JS:
Data Localization and Translation
Address formatting
Result: Mr. John S. Doe Jr.
Oro Inc.
Random str., 3, 14
LOS ANGELES CA US 12345
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Formatter/AddressFormatter.php
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/public/js/formatter/addr
ess.js
Data Localization and Translation
Datetime formatting
- Datetime values are formatted based on locale,
timezone and type (none, short, medium, long,
full)
- Datetime format configuration extracted from
libicu via PHP INTL extension
- Datetime formatter accepts DateTime object,
string and timestamp values
Data Localization and Translation
Datetime formatting
PHP: $dateTime = new DateTime(
'2011-12-13 14:15:16',
new DateTimeZone('UTC')
);
$formatter = $this->get('oro_locale.formatter.date_time');
$formatter->format($dateTime);
$formatter->formatDate($dateTime->format('Y-m-d'));
$formatter->formatTime($dateTime->getTimestamp());
Result: Dec 13, 2011 4:15 PM
Dec 13, 2011
4:15 PM
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Formatter/DateTimeFormatter.php
Data Localization and Translation
Datetime formatting
JS: require(['orolocale/js/formatter/datetime'],
function(datetimeFormatter) {
datetimeFormatter.formatDateTime('2011-12-13T14:15:16+0000');
datetimeFormatter.formatDate('2011-12-13');
datetimeFormatter.formatTime('14:15:16');
});
Twig: {{ '2011-12-13 14:15:16'|oro_format_datetime }}
{{ '2011-12-13'|oro_format_date }}
{{ '14:15:16'|oro_format_time }}
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/public/js/formatter/da
tetime.js
Result: Dec 13, 2011 4:15 PM
Dec 13, 2011
2:15 PM
Data Localization and Translation
Datetime format handling
- Different libraries use different datetime formats
- Oro Platform provides format converters for
libicu, moment.js and jquery.ui
- New formatters can be registered using DI tag
oro_locale.format_converter.date_time
Data Localization and Translation
Datetime timezone handling
- To simplify timezone handling all DateTime
object in the backend should be in UTC
timezone
- DateTime objects saved to the DB and
extracted from the DB are automatically
converted to UTC timezone
- Formatting of DateTime objects should be
performed using DateTimeConverter via
service oro_locale.formatter.date_time
Data Localization and Translation
Number formatting
- Numbers are formatted based on locale
- Formatter works with decimal, percent, currency,
spellout, duration and ordinal values
- Number format configuration extracted from
libicu via PHP INTL extension
- Currency use symbols from YAML files
Resources/config/oro/currency_data.yml
Data Localization and Translation
Number formatting
$formatter = $this->get('oro_locale.formatter.number');
$formatter->formatDecimal(12345.6789);
$formatter->formatDecimal(12345);
$formatter->formatPercent(1.2345);
$formatter->formatCurrency(12345.6789);
$formatter->formatCurrency(12345.6789, 'EUR');
PHP:
Twig: {{ 12345.6789|oro_format_decimal }}
{{ 12345|oro_format_decimal }}
{{ 1.2345|oro_format_percent }}
{{ 12345.6789|oro_format_currency }}
{{ 12345.6789|oro_format_currency({'currency':'EUR'}) }}
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Formatter/NumberFormatter.php
Data Localization and Translation
Number formatting
require(['orolocale/js/formatter/number'],
function(numberFormatter) {
numberFormatter.formatDecimal(12345.6789);
numberFormatter.formatInteger(12345);
numberFormatter.formatPercent(1.2345);
numberFormatter.formatCurrency(12345.6789);
numberFormatter.formatCurrency(12345.6789, 'EUR');
});
JS:
Result: 12,345.679
12,345
123.45%
$12,345.68
€12,345.68
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/public/js/formatter/nu
mber.js
Data Localization and Translation
Localization CLI commands
oro:localization:dump - dump localization
configuration from YAML files to
web/js/oro.locale_data.js
Data Localization and Translation
Translation is the communication of the
meaning of a source-language text by
means of an equivalent target-language text.
What is translation?
Data Localization and Translation
Oro Platform use standard Symfony2 mechanism
to perform frontend translation in PHP, in Twig
templates, and translator.js library from
BazingaJsTranslationBundle
Translations are stored in YAML files in any bundle
and in the application database.
How translations used in
Oro Platform?
Data Localization and Translation
- messages - common messages used both for
system and custom purposes
- validators - validation messages
- jsmessages - messages translated on frontend
side
- tooltips - messages for and form field tooltips
- entity - data for entities translated with Gedmo
translatable extension
Translation domains
Data Localization and Translation
Recommended
translation message format
<application>.<bundle>.<section>.<key>
oro.user.form.choose_gender
oro.dataaudit.change_history.title
oro.entity_config.menu.entities_list.label
Format:
Examples:
Data Localization and Translation
Translation extractors
- PhpCodeExtractor - extracts formatted
strings from PHP code
- NavigationTranslationExtractor -
extracts title translations from
navigation.yml files
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/TranslationBundle/Extractor/PhpCodeEx
tractor.php
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/NavigationBundle/Title/TranslationExtrac
tor.php
Data Localization and Translation
Translation on backend
$this->get('translator')->trans('oro.dashboard.title.main');
$this->get('translator')->trans('oro.entity.item', ['%id%' => 42]);
PHP:
Twig: {{ 'oro.dashboard.title.main'|trans }}
{{ 'oro.entity.item'|trans({'%id%': 42}) }}
Result: Dashboard
Item #42
# messages.en.yml
oro.dashboard.title.main: "Dashboard"
oro.entity.item: "Item #%id%"
YAML:
Data Localization and Translation
Translation on frontend
require(['orotranslation/js/translator'],
function(__) {
__('oro.note.add_note_title');
__('oro.datagrid.pagination.totalRecords', {totalRecords: 42});
});
JS:
Result: Add note
Total of 42 records
# jsmessages.en.yml
oro.note.add_note_title: "Add note"
oro.datagrid.pagination:
totalRecords: "Total of {{ totalRecords }} records"
YAML:
Data Localization and Translation
Translation in the database
- table oro_translation
- entity OroTranslationBundle:Translation
- scopes SYSTEM and UI
# id
# key
# value
# locale
# domain
# scope
Translation
Data Localization and Translation
Translation in database
- OrmTranslationLoader - loads
translations from database
- DatabasePersister - persists translations
to database
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/TranslationBundle/Translation/Or
mTranslationLoader.php
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/TranslationBundle/Translation/Da
tabasePersister.php
Data Localization and Translation
Translation configuration
System > Configuration > Language settings
Data Localization and Translation
Interaction with Crowdin
- Dump translations from translation extractors
and YAML files
- Download translations from Crowdin
- Merge them with existing translations
- Upload updated translations to Crowdin
Oro Platform Crowdin
1. dump 2. download
3. merge
4. upload
Data Localization and Translation
Debug translator
- Wraps translated strings in square brackets -
[<string>]
- Wraps not translated strings into exclamation
marks - !!!---string---!!!
- Add JS prefix for frontend translations
- can be enabled in app/config/config.yml
oro_translation:
debug_translator: true
https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/TranslationBundle/Translation/De
bugTranslator.php
Data Localization and Translation
Debug translator
Data Localization and Translation
Translation CLI commands
oro:translation:dump - dumps frontend
translations into web/js/translation/<locale>.js
oro:translation:pack - extracts translation files
for each bundle in specified vendor namespace
and creates language pack
Data Localization and Translation
Questions
and
Answers

More Related Content

What's hot

Web注入+http漏洞等描述
Web注入+http漏洞等描述Web注入+http漏洞等描述
Web注入+http漏洞等描述
fangjiafu
 
03 form-data
03 form-data03 form-data
03 form-data
snopteck
 

What's hot (20)

Slim Framework
Slim FrameworkSlim Framework
Slim Framework
 
55 New Features in Java 7
55 New Features in Java 755 New Features in Java 7
55 New Features in Java 7
 
Jstl Guide
Jstl GuideJstl Guide
Jstl Guide
 
JSP Standard Tag Library
JSP Standard Tag LibraryJSP Standard Tag Library
JSP Standard Tag Library
 
Building Data Mapper PHP5
Building Data Mapper PHP5Building Data Mapper PHP5
Building Data Mapper PHP5
 
What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3What's new, what's hot in PHP 5.3
What's new, what's hot in PHP 5.3
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
JSP Standart Tag Lİbrary - JSTL
JSP Standart Tag Lİbrary - JSTLJSP Standart Tag Lİbrary - JSTL
JSP Standart Tag Lİbrary - JSTL
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
JavaScript
JavaScriptJavaScript
JavaScript
 
JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) Bridge
 
PHP - Introduction to PHP Date and Time Functions
PHP -  Introduction to  PHP Date and Time FunctionsPHP -  Introduction to  PHP Date and Time Functions
PHP - Introduction to PHP Date and Time Functions
 
8 Minutes On Rack
8 Minutes On Rack8 Minutes On Rack
8 Minutes On Rack
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHP
 
Core Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug HuntCore Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug Hunt
 
Web注入+http漏洞等描述
Web注入+http漏洞等描述Web注入+http漏洞等描述
Web注入+http漏洞等描述
 
Wt unit 5
Wt unit 5Wt unit 5
Wt unit 5
 
03 form-data
03 form-data03 form-data
03 form-data
 
Java JDBC
Java JDBCJava JDBC
Java JDBC
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 

Similar to Data Localization and Translation

I18n
I18nI18n
I18n
soon
 
OWB11gR2 - Extending ETL
OWB11gR2 - Extending ETL OWB11gR2 - Extending ETL
OWB11gR2 - Extending ETL
Suraj Bang
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
Hugo Hamon
 

Similar to Data Localization and Translation (20)

I18n
I18nI18n
I18n
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP Applications
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
 
Zend framework 06 - zend config, pdf, i18n, l10n, sessions
Zend framework 06 - zend config, pdf, i18n, l10n, sessionsZend framework 06 - zend config, pdf, i18n, l10n, sessions
Zend framework 06 - zend config, pdf, i18n, l10n, sessions
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Migrating from drupal to plone with transmogrifier
Migrating from drupal to plone with transmogrifierMigrating from drupal to plone with transmogrifier
Migrating from drupal to plone with transmogrifier
 
Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011
 
OWB11gR2 - Extending ETL
OWB11gR2 - Extending ETL OWB11gR2 - Extending ETL
OWB11gR2 - Extending ETL
 
PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersPHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4Developers
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
The Ruby On Rails I18n Core Api
The Ruby On Rails I18n Core ApiThe Ruby On Rails I18n Core Api
The Ruby On Rails I18n Core Api
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
Rapid Prototyping with PEAR
Rapid Prototyping with PEARRapid Prototyping with PEAR
Rapid Prototyping with PEAR
 
PHP and COM
PHP and COMPHP and COM
PHP and COM
 
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
 
Internationalization with TYPO3
Internationalization with TYPO3Internationalization with TYPO3
Internationalization with TYPO3
 
How to Get Your Website Into the Cloud
How to Get Your Website Into the CloudHow to Get Your Website Into the Cloud
How to Get Your Website Into the Cloud
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
Client-side JavaScript Vulnerabilities
Client-side JavaScript VulnerabilitiesClient-side JavaScript Vulnerabilities
Client-side JavaScript Vulnerabilities
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web apps
 

More from Yevhen Shyshkin

More from Yevhen Shyshkin (6)

Development Guide for Beginners
Development Guide for BeginnersDevelopment Guide for Beginners
Development Guide for Beginners
 
Advanced Search with Elasticsearch
Advanced Search with ElasticsearchAdvanced Search with Elasticsearch
Advanced Search with Elasticsearch
 
E-Commerce search with Elasticsearch
E-Commerce search with ElasticsearchE-Commerce search with Elasticsearch
E-Commerce search with Elasticsearch
 
Code Review Best Practices
Code Review Best PracticesCode Review Best Practices
Code Review Best Practices
 
Transactions etc
Transactions etcTransactions etc
Transactions etc
 
Oro Workflows
Oro WorkflowsOro Workflows
Oro Workflows
 

Recently uploaded

AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 

Recently uploaded (20)

Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 

Data Localization and Translation

  • 1. Data Localization and Translation Data Localization and Translation Yevhen Shyshkin yshyshkin@orocrm.com https://github.com/yshyshkin
  • 2. Data Localization and Translation Language localisation is the process of adapting a product that has been previously translated into different languages to a specific country or region. What is language localization?
  • 3. Data Localization and Translation Where localization is applied? - Name formatting - Address formatting - Datetime formatting - Number formatting - Decimal - Integer - Percent - Currency
  • 4. Data Localization and Translation Localization configuration System > Configuration > Localization
  • 5. Data Localization and Translation Localization configuration $this->get('oro_locale.settings')->getLocale(); $this->get('oro_locale.settings')->getCurrency(); https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Model/LocaleSettings.php https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/public/js/locale- settings.js Result: en USD PHP: JS: require(['orolocale/js/locale-settings'], function(localeSettings) { localeSettings.getLocale(); localeSettings.getCurrency(); }); Twig: {{ oro_locale() }} {{ oro_currency() }}
  • 6. Data Localization and Translation Name formatting - Names are formatted based on locale - Name format configuration can be defined in any bundle’s YAML file Resources/config/oro/name_format.yml - Format may contain placeholders for name prefix, name suffix, first name, last name and middle name - Entity must include OroBundle LocaleBundleModelFullNameInterface https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Model/FullNameInterface.php
  • 7. Data Localization and Translation Name formatting en: %prefix% %first_name% %middle_name% %last_name% %suffix% en_US: %prefix% %first_name% %middle_name% %last_name% %suffix% ru: %last_name% %first_name% %middle_name% ru_RU: %last_name% %first_name% %middle_name% Configuration example https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/config/oro/na me_format.yml
  • 8. Data Localization and Translation Name formatting $user = new User(); // implements FullNameInterface $user->setNamePrefix('Mr.') ->setFirstName('John') ->setMiddleName('S.') ->setLastName('Doe') ->setNameSuffix('Jr.'); $this->get('oro_locale.formatter.name')->format($user); $this->get('oro_locale.formatter.name')->format($user, 'ru'); PHP: Twig: {{ entity|oro_format_name }} {{ entity|oro_format_name('ru') }} https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Formatter/NameFormatter.php
  • 9. Data Localization and Translation Name formatting require(['orolocale/js/formatter/name'], function(nameFormatter) { var user = { 'prefix': 'Mr.', 'first_name': 'John', 'middle_name': 'S.', 'last_name': 'Doe', 'suffix': 'Jr' }; nameFormatter.format(user); nameFormatter.format(user, 'ru'); }); JS: Result: Mr. John S. Doe Jr. Doe John S. https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/public/js/formatter/na me.js
  • 10. Data Localization and Translation Address formatting - Addresses are formatted based on primary location or country address - Address format configuration can be defined in any bundle’s YAML file Resources/config/oro/address_format.yml - Format may contain placeholders for name, organization, street, city, region, region code, country, country code and postal code - Entity must include OroBundle LocaleBundleModelAddressInterface https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Model/AddressInterface.php
  • 11. Data Localization and Translation Address formatting US: format: '%name%n%organization%n%street%n%CITY% %REGION_CODE% %COUNTRY_ISO2% %postal_code%' require: [street, city, region, postal_code] zip_name_type: zip region_name_type: region RU: format: '%postal_code% %COUNTRY% %CITY%n%STREET%n%organization%n%name%' require: [street, city, postal_code] Configuration example https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/config/oro/ad dress_format.yml
  • 12. Data Localization and Translation Address formatting $country = new Country('US'); $country->setName('United States of America') ->setIso3Code('USA'); $region = new Region('US-CA'); $region->setCode('CA') ->setName('California'); $address = new Address(); // implements AddressInterface $address->setNamePrefix('Mr.') ->setFirstName('John') ->setMiddleName('S.') ->setLastName('Doe') ->setNameSuffix('Jr.'); $address->setStreet('Random str., 3, 14') ->setCity('Los Angeles') ->setRegion($region) ->setCountry($country) ->setPostalCode('12345') ->setOrganization('Oro Inc.'); $this->get('oro_locale.formatter.address')->format($address); PHP:
  • 13. Data Localization and Translation Address formatting Twig: {{ address|oro_format_address|nl2br }} require(['orolocale/js/formatter/address'], function(addressFormatter) { var address = { 'prefix': 'Mr.', 'first_name': 'John', 'middle_name': 'S.', 'last_name': 'Doe', 'suffix': 'Jr', 'organization': 'Oro Inc.', 'street': 'Random str., 3, 14', 'city': 'Los Angeles', 'region_code': 'CA', 'country_iso2': 'US', 'postal_code': '12345' }; addressFormatter.format(address); }); JS:
  • 14. Data Localization and Translation Address formatting Result: Mr. John S. Doe Jr. Oro Inc. Random str., 3, 14 LOS ANGELES CA US 12345 https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Formatter/AddressFormatter.php https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/public/js/formatter/addr ess.js
  • 15. Data Localization and Translation Datetime formatting - Datetime values are formatted based on locale, timezone and type (none, short, medium, long, full) - Datetime format configuration extracted from libicu via PHP INTL extension - Datetime formatter accepts DateTime object, string and timestamp values
  • 16. Data Localization and Translation Datetime formatting PHP: $dateTime = new DateTime( '2011-12-13 14:15:16', new DateTimeZone('UTC') ); $formatter = $this->get('oro_locale.formatter.date_time'); $formatter->format($dateTime); $formatter->formatDate($dateTime->format('Y-m-d')); $formatter->formatTime($dateTime->getTimestamp()); Result: Dec 13, 2011 4:15 PM Dec 13, 2011 4:15 PM https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Formatter/DateTimeFormatter.php
  • 17. Data Localization and Translation Datetime formatting JS: require(['orolocale/js/formatter/datetime'], function(datetimeFormatter) { datetimeFormatter.formatDateTime('2011-12-13T14:15:16+0000'); datetimeFormatter.formatDate('2011-12-13'); datetimeFormatter.formatTime('14:15:16'); }); Twig: {{ '2011-12-13 14:15:16'|oro_format_datetime }} {{ '2011-12-13'|oro_format_date }} {{ '14:15:16'|oro_format_time }} https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/public/js/formatter/da tetime.js Result: Dec 13, 2011 4:15 PM Dec 13, 2011 2:15 PM
  • 18. Data Localization and Translation Datetime format handling - Different libraries use different datetime formats - Oro Platform provides format converters for libicu, moment.js and jquery.ui - New formatters can be registered using DI tag oro_locale.format_converter.date_time
  • 19. Data Localization and Translation Datetime timezone handling - To simplify timezone handling all DateTime object in the backend should be in UTC timezone - DateTime objects saved to the DB and extracted from the DB are automatically converted to UTC timezone - Formatting of DateTime objects should be performed using DateTimeConverter via service oro_locale.formatter.date_time
  • 20. Data Localization and Translation Number formatting - Numbers are formatted based on locale - Formatter works with decimal, percent, currency, spellout, duration and ordinal values - Number format configuration extracted from libicu via PHP INTL extension - Currency use symbols from YAML files Resources/config/oro/currency_data.yml
  • 21. Data Localization and Translation Number formatting $formatter = $this->get('oro_locale.formatter.number'); $formatter->formatDecimal(12345.6789); $formatter->formatDecimal(12345); $formatter->formatPercent(1.2345); $formatter->formatCurrency(12345.6789); $formatter->formatCurrency(12345.6789, 'EUR'); PHP: Twig: {{ 12345.6789|oro_format_decimal }} {{ 12345|oro_format_decimal }} {{ 1.2345|oro_format_percent }} {{ 12345.6789|oro_format_currency }} {{ 12345.6789|oro_format_currency({'currency':'EUR'}) }} https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Formatter/NumberFormatter.php
  • 22. Data Localization and Translation Number formatting require(['orolocale/js/formatter/number'], function(numberFormatter) { numberFormatter.formatDecimal(12345.6789); numberFormatter.formatInteger(12345); numberFormatter.formatPercent(1.2345); numberFormatter.formatCurrency(12345.6789); numberFormatter.formatCurrency(12345.6789, 'EUR'); }); JS: Result: 12,345.679 12,345 123.45% $12,345.68 €12,345.68 https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/LocaleBundle/Resources/public/js/formatter/nu mber.js
  • 23. Data Localization and Translation Localization CLI commands oro:localization:dump - dump localization configuration from YAML files to web/js/oro.locale_data.js
  • 24. Data Localization and Translation Translation is the communication of the meaning of a source-language text by means of an equivalent target-language text. What is translation?
  • 25. Data Localization and Translation Oro Platform use standard Symfony2 mechanism to perform frontend translation in PHP, in Twig templates, and translator.js library from BazingaJsTranslationBundle Translations are stored in YAML files in any bundle and in the application database. How translations used in Oro Platform?
  • 26. Data Localization and Translation - messages - common messages used both for system and custom purposes - validators - validation messages - jsmessages - messages translated on frontend side - tooltips - messages for and form field tooltips - entity - data for entities translated with Gedmo translatable extension Translation domains
  • 27. Data Localization and Translation Recommended translation message format <application>.<bundle>.<section>.<key> oro.user.form.choose_gender oro.dataaudit.change_history.title oro.entity_config.menu.entities_list.label Format: Examples:
  • 28. Data Localization and Translation Translation extractors - PhpCodeExtractor - extracts formatted strings from PHP code - NavigationTranslationExtractor - extracts title translations from navigation.yml files https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/TranslationBundle/Extractor/PhpCodeEx tractor.php https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/NavigationBundle/Title/TranslationExtrac tor.php
  • 29. Data Localization and Translation Translation on backend $this->get('translator')->trans('oro.dashboard.title.main'); $this->get('translator')->trans('oro.entity.item', ['%id%' => 42]); PHP: Twig: {{ 'oro.dashboard.title.main'|trans }} {{ 'oro.entity.item'|trans({'%id%': 42}) }} Result: Dashboard Item #42 # messages.en.yml oro.dashboard.title.main: "Dashboard" oro.entity.item: "Item #%id%" YAML:
  • 30. Data Localization and Translation Translation on frontend require(['orotranslation/js/translator'], function(__) { __('oro.note.add_note_title'); __('oro.datagrid.pagination.totalRecords', {totalRecords: 42}); }); JS: Result: Add note Total of 42 records # jsmessages.en.yml oro.note.add_note_title: "Add note" oro.datagrid.pagination: totalRecords: "Total of {{ totalRecords }} records" YAML:
  • 31. Data Localization and Translation Translation in the database - table oro_translation - entity OroTranslationBundle:Translation - scopes SYSTEM and UI # id # key # value # locale # domain # scope Translation
  • 32. Data Localization and Translation Translation in database - OrmTranslationLoader - loads translations from database - DatabasePersister - persists translations to database https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/TranslationBundle/Translation/Or mTranslationLoader.php https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/TranslationBundle/Translation/Da tabasePersister.php
  • 33. Data Localization and Translation Translation configuration System > Configuration > Language settings
  • 34. Data Localization and Translation Interaction with Crowdin - Dump translations from translation extractors and YAML files - Download translations from Crowdin - Merge them with existing translations - Upload updated translations to Crowdin Oro Platform Crowdin 1. dump 2. download 3. merge 4. upload
  • 35. Data Localization and Translation Debug translator - Wraps translated strings in square brackets - [<string>] - Wraps not translated strings into exclamation marks - !!!---string---!!! - Add JS prefix for frontend translations - can be enabled in app/config/config.yml oro_translation: debug_translator: true https://github.com/orocrm/platform/blob/1.6.0/src/Oro/Bundle/TranslationBundle/Translation/De bugTranslator.php
  • 36. Data Localization and Translation Debug translator
  • 37. Data Localization and Translation Translation CLI commands oro:translation:dump - dumps frontend translations into web/js/translation/<locale>.js oro:translation:pack - extracts translation files for each bundle in specified vendor namespace and creates language pack
  • 38. Data Localization and Translation Questions and Answers