Tml for Laravel

43
Powered by Translation Exchange Translation Markup Language for Laravel TranslationExchange.com

Transcript of Tml for Laravel

Powered by Translation Exchange

Translation Markup Language for Laravel

TranslationExchange.com

Michael [email protected]

@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 .xmlApple .stringsApple .plistGettext .poGettext .potJava .properties Java .xmlMicrosoft .resxMicrosoft .reswMicrosoft .resjsonMicrosoft .aspx

FILE FORMATSLots of translation

Microsoft .rcPHP .iniPHP .confLaravel .phpBlackberry .rrcNSIS .inshQT Linguist .tsLatex .latexDocbook .dbkTBX .tbxTMX .tmx

XLIFF .xliffYouTube .sbvRails YAML .yamlSubtitles .srtMicroDVD .subSubviewer .subMozilla Web L10NText .txtCSV SpreadsheetExcel SpreadsheetWord 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

BOTTLENECKFile 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 itBETTER FOR EVERYONE

TranslationExchange.com

What would an ideal solution look like?

● ConsistencyProvide tools that offer a clear and

consistent way for internationalizing

content across all frameworks

● AdaptabilityTools must be extensible and adaptable

and should be able to solve any arising

internationalization and localization

problem

● ContextualizationAllow translators to translate in context

from within the application

● AgilityKeep 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 CDNLocal Cache

Laravel Application with TML SDK

A Better WayAn integrated and truly automated continuous localization

TranslationExchange.com

Translation CachingStatic and dynamic cache adapters for storing translations in your application

Inline Translation ToolsTranslation can be done in context of the application

Access Professional TranslatorsConnect your application to thousands of professional translators around the world

Open SourceAll SDKs are available on github

Multiple PlatformsSupport for PHP, Laravel, Rails, Node, Python, iOS, Android and more

Universal Translation MemoryTranslations 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 = [...

\App\Http\Middleware\Tml::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 ExtractionEntire 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

TMLDEMO

Caching Options

Static CacheFile based cache. Loaded into the process memory and must be deployed with the source code. Each process contains the entire translation cache.

Dynamic CacheRedis, 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 Translationprovided by Google, Microsoft and Yandex. Translations are ranked to get the best result.

Crowdsourced TranslationSome developers may choose to use their own users to translate their content, similar to how Facebook and Twitter translated their sites.

Professional TranslationOrder are received and processed by our partners and are made available in our system within hours.

TranslationExchange.com

UNIVERSAL TRANSLATIONMEMORY

● 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

ResourcesSDKs 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 [email protected]

We’re Hiring!

Thank youQUESTIONS?