KEMBAR78
Tml for Laravel | PDF
Powered by Translation Exchange
Translation Markup Language
for Laravel
TranslationExchange.com
Michael Berkovich
michael@translationexchange.com
@translationx
TranslationExchange.com
Localization is hard
There are many
standards, but little
guidance.
“
Every i18n framework has its own “right way”
of doing things, with a different syntax and file
format.
Developers often hack together their own
solutions to try and simplify the process.
No universality
in the current
standards
Android .xml
Apple .strings
Apple .plist
Gettext .po
Gettext .pot
Java .properties
Java .xml
Microsoft .resx
Microsoft .resw
Microsoft .resjson
Microsoft .aspx
FILE FORMATS
Lots of translation
Microsoft .rc
PHP .ini
PHP .conf
Laravel .php
Blackberry .rrc
NSIS .insh
QT Linguist .ts
Latex .latex
Docbook .dbk
TBX .tbx
TMX .tmx
XLIFF .xliff
YouTube .sbv
Rails YAML .yaml
Subtitles .srt
MicroDVD .sub
Subviewer .sub
Mozilla Web L10N
Text .txt
CSV Spreadsheet
Excel Spreadsheet
Word Document
Extract content into
files
Upload files to a TMS
or an LSP
Wait... Download translated
files
Put translations back
in your app
Repeat when new content is added or changed
BOTTLENECK
File management is a
File Management
● Not DRY (Don’t Repeat Yourself)
● Requires content extraction, sync with a TMS or an LSP
● Mini “waterfalls” in the agile process
● Slows down development cycle and releases
● High upfront cost and maintenance
How can we make it
BETTER FOR
EVERYONE
TranslationExchange.com
What would an ideal solution
look like?
● Consistency
Provide tools that offer a clear and
consistent way for internationalizing
content across all frameworks
● Adaptability
Tools must be extensible and adaptable
and should be able to solve any arising
internationalization and localization
problem
● Contextualization
Allow translators to translate in context
from within the application
● Agility
Keep the development cycle agile -
localization must not add significant
overhead for developers - it must be done
in parallel to the development process
TranslationExchange.com
あ
A
Translation Management
Service
Global CDN
Local Cache
Laravel Application
with TML SDK
A Better Way
An integrated and truly automated continuous localization
TranslationExchange.com
Translation Caching
Static and dynamic cache adapters for
storing translations in your application
Inline Translation Tools
Translation can be done in context of the
application
Access Professional Translators
Connect your application to thousands of
professional translators around the world
Open Source
All SDKs are available on github
Multiple Platforms
Support for PHP, Laravel, Rails, Node,
Python, iOS, Android and more
Universal Translation Memory
Translations are shared across all
applications
Core Benefits of TML SDK
TranslationExchange.com
Getting Started
TranslationExchange.com
"require": {
"translationexchange/tml": "3.2.12"
}
Integration
// composer.json
TranslationExchange.com
Configuration
// app/Http/Middleware/Tml.php
public function handle($request, Closure $next) {
tml_init([
"key" => "YOUR_APP_KEY",
“cache” => [...]
]);
return $next($request);
}
public function terminate($request, $response) {
tml_complete_request();
}
TranslationExchange.com
Configuration
// app/Http/Kernel.php
protected $middleware = [
...
AppHttpMiddlewareTml::class,
...
];
TranslationExchange.com
Configuration
// resources/views/layouts/application.blade.php
// enable scripts
{!! tml_scripts_tag() !!}
// optionally, add default language selector
{!! tml_language_selector_tag("sideflags") !!}
TranslationExchange.com
Internationalization
// wrap strings with the tr method
{!! tr("Hello World") !!}
// use interpolation
{!! tr("Hello {user}", ["user" => "Michael"]) !!}
// and many other features of TML syntax...
{!! tr("You have {count || message}", ["count" => 5]) !!}
TranslationExchange.com
DEMO
Translation Markup Language
● Developer friendly syntax for marking up application text.
● Supports language context rules and language cases, making
translations accurate for any language.
TranslationExchange.com
TML for Laravel Basics
Hello World
“tr” method is available in Rails, PHP, Java, Obj C, Python, Javascript, Node.JS, Ember, Angular, etc...
{!! tr('Hello World') !!}
Descriptions
tr('Eats shoots and leaves', 'a panda')
Eats shoots and leaves
tr('Eats shoots and leaves', 'a violent restaurant patron')
Interpolation
tr('Hello {name}', ['name' => 'John'])
Hello John
Decoration Tokens
tr('Hello [bold: World]', ['bold’ => '<strong>{$0}</strong>'])
Hello WorldWorld
Decoration Tokens
tr('Hello <indent>World</indent>', ['indent’ => '<strong>{$0}</strong>'])
tr('Hello <strong>World</strong>')
Hello WorldWorld
or
Decoration Tokens
tr('Hello <link>World</link>', ['link’ => [‘href’ => ‘www.google.com’]])
link: ‘<a href=”{$href}”>{$0}</a>’
Hello WorldWorld
where link is a default decoration defined as
Reusing Decoration Tokens
in Other Frameworks (Obj C)
TMLLocalizedString('Hello <bold>World</bold>', @{
@”bold”: @{
@"font": [UIFont fontWithName:@"ChalkboardSE-Bold" size:14]
}
})
iOS Uses Native Decoration Methods
Hello WorldWorld
tr('[link1: {user}] completed [bold: {count || mile}] on
[link2: {user | his, her} last run].',
[
'user’ => $run->user,
'count’ => $run->miles,
'link1’ => [‘href’ => $run->user->url()]],
'link2’ => [‘href’ => $run->url()]],
]
)
More Complex Example
Michael completed 3 miles on his last run.
{!! tml_begin_source('/common/navigation') }}
<ul>
<li>{!! tr('Home') !!}</li>
<li>{!! tr('Features') !!}</li>
<li>{!! tr('Languages') !!}</li>
<li>{!! tr('Pricing') !!}</li>
<li>{!! tr('Docs') !!}</li>
</ul>
{!! tml_finish_source() }}
Sources are arbitrary groups of related translation keys
Sources
{!! trh(“
<ul>
<li>Home</li>
<li>Features</li>
<li>Languages</li>
<li>Pricing</li>
<li>Docs</li>
</ul>
“, [], ['source' => '/common/navigation'] !!}
Automatic String Extraction
Entire blocks can be translated without markup.
{!! trh(“
<nav>
<ul>
<li>You have <a href=’/messages’>unread messages</a></li>
<li><a href=’/logout’>Logout</a></li>
</ul>
</nav>
“, [], ['source' => '/common/navigation'] !!}
Automatic TML Conversion
You have [link: unread messages]
You have unread messages
tr('Welcome to {user::pos} blog.', [
'user’ => 'Michael’
])
Language Cases
Welcome to Michael’s blog.
Ordinals
This is your second warning
tr('This is your {count::ord} warning', [
'count’ => 2
])
TranslationExchange.com
TML
DEMO
Caching Options
Static Cache
File based cache. Loaded into the process
memory and must be deployed with the
source code. Each process contains the
entire translation cache.
Dynamic Cache
Redis, Memcached (and others) updated
from CDN release. Cache is shared
across all processes. Can be deployed
without restarting servers.
TranslationExchange.com
How is Translation Done?
Machine Translation
provided by Google,
Microsoft and Yandex.
Translations are ranked to
get the best result.
Crowdsourced Translation
Some developers may
choose to use their own
users to translate their
content, similar to how
Facebook and Twitter
translated their sites.
Professional Translation
Order are received and
processed by our partners
and are made available in our
system within hours.
TranslationExchange.com
UNIVERSAL
TRANSLATION
MEMORY
● Translations should be reusable across
multiple projects
● Each translation key can have many
translation options for a language based
on context
● Translation keys and translations are
unique and are only stored once in the
entire system
What is UTM?
Hello World Hola Mundo
안녕하세요
Привет Мир
Hallo Welt ‫עולם‬ ‫שלום‬
你好,世界
UTM Graph
SUMMARY
& CONCLUSION
Resources
SDKs https://github.com/translationexchange
Documentation http://translationexchange.com/docs
Blog http://blog.translationexchange.com
Live Sample App http://foody.translationexchange.com
Facebook https://www.facebook.com/translationexchange
Twitter @translationx
Feedback feedback@translationexchange.com
We’re Hiring!
Thank you
QUESTIONS?

Tml for Laravel

  • 1.
    Powered by TranslationExchange Translation Markup Language for Laravel TranslationExchange.com
  • 2.
  • 3.
  • 4.
    There are many standards,but little guidance. “
  • 5.
    Every i18n frameworkhas its own “right way” of doing things, with a different syntax and file format. Developers often hack together their own solutions to try and simplify the process. No universality in the current standards
  • 6.
    Android .xml Apple .strings Apple.plist Gettext .po Gettext .pot Java .properties Java .xml Microsoft .resx Microsoft .resw Microsoft .resjson Microsoft .aspx FILE FORMATS Lots of translation Microsoft .rc PHP .ini PHP .conf Laravel .php Blackberry .rrc NSIS .insh QT Linguist .ts Latex .latex Docbook .dbk TBX .tbx TMX .tmx XLIFF .xliff YouTube .sbv Rails YAML .yaml Subtitles .srt MicroDVD .sub Subviewer .sub Mozilla Web L10N Text .txt CSV Spreadsheet Excel Spreadsheet Word Document
  • 7.
    Extract content into files Uploadfiles to a TMS or an LSP Wait... Download translated files Put translations back in your app Repeat when new content is added or changed BOTTLENECK File management is a
  • 8.
    File Management ● NotDRY (Don’t Repeat Yourself) ● Requires content extraction, sync with a TMS or an LSP ● Mini “waterfalls” in the agile process ● Slows down development cycle and releases ● High upfront cost and maintenance
  • 9.
    How can wemake it BETTER FOR EVERYONE TranslationExchange.com
  • 10.
    What would anideal solution look like? ● Consistency Provide tools that offer a clear and consistent way for internationalizing content across all frameworks ● Adaptability Tools must be extensible and adaptable and should be able to solve any arising internationalization and localization problem ● Contextualization Allow translators to translate in context from within the application ● Agility Keep the development cycle agile - localization must not add significant overhead for developers - it must be done in parallel to the development process TranslationExchange.com
  • 11.
    あ A Translation Management Service Global CDN LocalCache Laravel Application with TML SDK A Better Way An integrated and truly automated continuous localization TranslationExchange.com
  • 12.
    Translation Caching Static anddynamic cache adapters for storing translations in your application Inline Translation Tools Translation can be done in context of the application Access Professional Translators Connect your application to thousands of professional translators around the world Open Source All SDKs are available on github Multiple Platforms Support for PHP, Laravel, Rails, Node, Python, iOS, Android and more Universal Translation Memory Translations are shared across all applications Core Benefits of TML SDK TranslationExchange.com
  • 13.
  • 14.
  • 15.
    Configuration // app/Http/Middleware/Tml.php public functionhandle($request, Closure $next) { tml_init([ "key" => "YOUR_APP_KEY", “cache” => [...] ]); return $next($request); } public function terminate($request, $response) { tml_complete_request(); } TranslationExchange.com
  • 16.
    Configuration // app/Http/Kernel.php protected $middleware= [ ... AppHttpMiddlewareTml::class, ... ]; TranslationExchange.com
  • 17.
    Configuration // resources/views/layouts/application.blade.php // enablescripts {!! tml_scripts_tag() !!} // optionally, add default language selector {!! tml_language_selector_tag("sideflags") !!} TranslationExchange.com
  • 18.
    Internationalization // wrap stringswith the tr method {!! tr("Hello World") !!} // use interpolation {!! tr("Hello {user}", ["user" => "Michael"]) !!} // and many other features of TML syntax... {!! tr("You have {count || message}", ["count" => 5]) !!} TranslationExchange.com
  • 19.
  • 20.
    Translation Markup Language ●Developer friendly syntax for marking up application text. ● Supports language context rules and language cases, making translations accurate for any language. TranslationExchange.com
  • 21.
    TML for LaravelBasics Hello World “tr” method is available in Rails, PHP, Java, Obj C, Python, Javascript, Node.JS, Ember, Angular, etc... {!! tr('Hello World') !!}
  • 22.
    Descriptions tr('Eats shoots andleaves', 'a panda') Eats shoots and leaves tr('Eats shoots and leaves', 'a violent restaurant patron')
  • 23.
  • 24.
    Decoration Tokens tr('Hello [bold:World]', ['bold’ => '<strong>{$0}</strong>']) Hello WorldWorld
  • 25.
    Decoration Tokens tr('Hello <indent>World</indent>',['indent’ => '<strong>{$0}</strong>']) tr('Hello <strong>World</strong>') Hello WorldWorld or
  • 26.
    Decoration Tokens tr('Hello <link>World</link>',['link’ => [‘href’ => ‘www.google.com’]]) link: ‘<a href=”{$href}”>{$0}</a>’ Hello WorldWorld where link is a default decoration defined as
  • 27.
    Reusing Decoration Tokens inOther Frameworks (Obj C) TMLLocalizedString('Hello <bold>World</bold>', @{ @”bold”: @{ @"font": [UIFont fontWithName:@"ChalkboardSE-Bold" size:14] } }) iOS Uses Native Decoration Methods Hello WorldWorld
  • 28.
    tr('[link1: {user}] completed[bold: {count || mile}] on [link2: {user | his, her} last run].', [ 'user’ => $run->user, 'count’ => $run->miles, 'link1’ => [‘href’ => $run->user->url()]], 'link2’ => [‘href’ => $run->url()]], ] ) More Complex Example Michael completed 3 miles on his last run.
  • 29.
    {!! tml_begin_source('/common/navigation') }} <ul> <li>{!!tr('Home') !!}</li> <li>{!! tr('Features') !!}</li> <li>{!! tr('Languages') !!}</li> <li>{!! tr('Pricing') !!}</li> <li>{!! tr('Docs') !!}</li> </ul> {!! tml_finish_source() }} Sources are arbitrary groups of related translation keys Sources
  • 30.
    {!! trh(“ <ul> <li>Home</li> <li>Features</li> <li>Languages</li> <li>Pricing</li> <li>Docs</li> </ul> “, [],['source' => '/common/navigation'] !!} Automatic String Extraction Entire blocks can be translated without markup.
  • 31.
    {!! trh(“ <nav> <ul> <li>You have<a href=’/messages’>unread messages</a></li> <li><a href=’/logout’>Logout</a></li> </ul> </nav> “, [], ['source' => '/common/navigation'] !!} Automatic TML Conversion You have [link: unread messages] You have unread messages
  • 32.
    tr('Welcome to {user::pos}blog.', [ 'user’ => 'Michael’ ]) Language Cases Welcome to Michael’s blog.
  • 33.
    Ordinals This is yoursecond warning tr('This is your {count::ord} warning', [ 'count’ => 2 ])
  • 34.
  • 35.
    Caching Options Static Cache Filebased cache. Loaded into the process memory and must be deployed with the source code. Each process contains the entire translation cache. Dynamic Cache Redis, Memcached (and others) updated from CDN release. Cache is shared across all processes. Can be deployed without restarting servers. TranslationExchange.com
  • 36.
    How is TranslationDone? Machine Translation provided by Google, Microsoft and Yandex. Translations are ranked to get the best result. Crowdsourced Translation Some developers may choose to use their own users to translate their content, similar to how Facebook and Twitter translated their sites. Professional Translation Order are received and processed by our partners and are made available in our system within hours. TranslationExchange.com
  • 37.
  • 38.
    ● Translations shouldbe reusable across multiple projects ● Each translation key can have many translation options for a language based on context ● Translation keys and translations are unique and are only stored once in the entire system What is UTM?
  • 39.
    Hello World HolaMundo 안녕하세요 Привет Мир Hallo Welt ‫עולם‬ ‫שלום‬ 你好,世界 UTM Graph
  • 40.
  • 41.
    Resources SDKs https://github.com/translationexchange Documentation http://translationexchange.com/docs Bloghttp://blog.translationexchange.com Live Sample App http://foody.translationexchange.com Facebook https://www.facebook.com/translationexchange Twitter @translationx Feedback feedback@translationexchange.com
  • 42.
  • 43.