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

Tml for Laravel

Jan 13, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Tml for Laravel

Powered by Translation Exchange

Translation Markup Language for Laravel

TranslationExchange.com

Page 2: Tml for Laravel

Michael [email protected]

@translationx

TranslationExchange.com

Page 3: Tml for Laravel

Localization is hard

Page 4: Tml for Laravel

There are many standards, but little guidance.

Page 5: Tml for Laravel

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

Page 6: Tml for Laravel

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

Page 7: Tml for Laravel

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

Page 8: Tml for Laravel

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

Page 9: Tml for Laravel

How can we make itBETTER FOR EVERYONE

TranslationExchange.com

Page 10: Tml for Laravel

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

Page 11: Tml for Laravel

あA

Translation Management Service

Global CDNLocal Cache

Laravel Application with TML SDK

A Better WayAn integrated and truly automated continuous localization

TranslationExchange.com

Page 12: Tml for Laravel

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

Page 13: Tml for Laravel

Getting Started

TranslationExchange.com

Page 14: Tml for Laravel

"require": { "translationexchange/tml": "3.2.12"}

Integration

// composer.json

TranslationExchange.com

Page 15: Tml for Laravel

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

Page 16: Tml for Laravel

Configuration

// app/Http/Kernel.php

protected $middleware = [...

\App\Http\Middleware\Tml::class,...

];

TranslationExchange.com

Page 17: Tml for Laravel

Configuration

// resources/views/layouts/application.blade.php

// enable scripts

{!! tml_scripts_tag() !!}

// optionally, add default language selector

{!! tml_language_selector_tag("sideflags") !!}

TranslationExchange.com

Page 18: Tml for Laravel

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

Page 19: Tml for Laravel

DEMO

Page 20: Tml for Laravel

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

Page 21: Tml for Laravel

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') !!}

Page 22: Tml for Laravel

Descriptions

tr('Eats shoots and leaves', 'a panda')

Eats shoots and leaves

tr('Eats shoots and leaves', 'a violent restaurant patron')

Page 23: Tml for Laravel

Interpolation

tr('Hello {name}', ['name' => 'John'])

Hello John

Page 24: Tml for Laravel

Decoration Tokens

tr('Hello [bold: World]', ['bold’ => '<strong>{$0}</strong>'])

Hello WorldWorld

Page 25: Tml for Laravel

Decoration Tokens

tr('Hello <indent>World</indent>', ['indent’ => '<strong>{$0}</strong>'])

tr('Hello <strong>World</strong>')

Hello WorldWorld

or

Page 26: Tml for Laravel

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

Page 27: Tml for Laravel

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

Page 28: Tml for Laravel

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.

Page 29: Tml for Laravel

{!! 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

Page 30: Tml for Laravel

{!! 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.

Page 31: Tml for Laravel

{!! 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

Page 32: Tml for Laravel

tr('Welcome to {user::pos} blog.', [ 'user’ => 'Michael’])

Language Cases

Welcome to Michael’s blog.

Page 33: Tml for Laravel

Ordinals

This is your second warning

tr('This is your {count::ord} warning', [ 'count’ => 2])

Page 34: Tml for Laravel

TranslationExchange.com

TMLDEMO

Page 35: Tml for Laravel

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

Page 36: Tml for Laravel

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

Page 37: Tml for Laravel

UNIVERSAL TRANSLATIONMEMORY

Page 38: Tml for Laravel

● 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?

Page 39: Tml for Laravel

Hello World Hola Mundo

안녕하세요Привет Мир

Hallo Welt שלום עולם

你好,世界

UTM Graph

Page 40: Tml for Laravel

SUMMARY& CONCLUSION

Page 41: Tml for Laravel

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]

Page 42: Tml for Laravel

We’re Hiring!

Page 43: Tml for Laravel

Thank youQUESTIONS?