tr8n for php - michael berkovich
DESCRIPTION
TRANSCRIPT
Tr8n for PHPCrowdsourced Translations
Presented by Michael [email protected]
https://github.com/tr8n/tr8n_php_clientsdk
About Me
● Software Engineer at Digital Evolution, US Interactive, SOA Software, Geni, Yammer
● Creator of Tr8n translation framework
● Founder and CTO at Tr8nHub.com
What is Tr8n?
Tr8n = Tr[anslatio]n
pronounced “tr - 8 - n”
Translation framework, platform, technology.
Started as a Ruby library to translate Geni.com to 70 languages.
RoR Gem is created and adopted by Yammer and a number of companies around the world. Tr8n Gem is open sourced.
Tr8nHub server (beta) is launched as a shared Translation Memory and Language Rule Repository.
Ruby, PHP, Objective C, JavaScript, C# and Java SDK libraries are added to support all major platforms.
Tr8n Timeline
2009
2010
2013
2014
Tr8n Core Features
● Translation Markup Language (TML)
● Rules Engine with Centralized Repository
● Shared Translation Memory (TM)
Additional Features
● No resource bundles● Support for over 300 languages ● Crowdsourced translation tools● Inline and bulk translation modes● Intuitive user interface and admin tools● Custom translation workflows● Glossaries, forums, etc...
Tr8n SDK + Tr8nHub
Your Application
PHP, Rails, Java,iOS, JavaScript, Python, Perl, .Net, etc...
Tr8nHub.comTM, Rules, UI
Widgets, Workflows, Management, etc...
CacheFiles, APC,
Memcache, Redis, CHDB, DB,...
Tr8n
SD
K API
Tr8n SDKs
● API Client
● Rules Engine + TML
● Cache Adapters
Tr8nHub Platform
● Translation Management● User Interface and Widgets● Shared Translation Memory● Translator Tools● Workflows, etc...
Translation Overview
Why Crowdsourcing?
● Use your own users to translate your application
● No “Golden Gate Bridge Syndrome”
● Self-monitoring and auditing system
● Low cost for adding new languages
Tr8n Ranking Systems
Translation rank - total sum of all positive and negative votes for a translation
Application threshold - the minimum translation rank to be displayed in an application
Translator rank - a ratio between the total submitted translations and accepted translations
Translation Rank
● When user adds a translation, it automatically gets +1 vote/rank
● User can only submit one vote for each translation
● Other users can vote +1 or -1 per translation
● Total sum of all +1 and -1 is the rank of the translation
Application Threshold
● Threshold controls which translations will be used in the application
● Lower number allows for more aggressive translations
● Higher number requires more users to vote before the translation is accepted
● Users may have different voting powers based on their ranks and levels
Translation Monitoring
● Each translation is checked against dirty word filters
● Bad translations are rejected and translators are put on the watch list
● Reported translations are not deleted, but voted -100 points
● Admin tools allow for close monitoring of the progress and identify violations
Translation States
Accepted - translation rank is above the application threshold
Pending - translation rank is between 0 and the application threshold
Rejected - translation rank is below 0
Levels & Permissions
● Each translation key and translator has a level
● By default all keys and all translators have level 0
● Translators can only translate keys at their level or below
● Levels can be assigned to keys and translators, or to entire sections of the app
Translator Rank
● Calculated every time translations are voted up or down
● Reporting a translation puts a translator on a watch list
● Translators can be blocked by admins and their translations can be automatically suspended or rejected
Managers
● Translators can be promoted to managers
● Managers get higher voting power
● Managers can configure application setting and language rules
Translation Key Locks
● Managers can lock and unlock translation keys for a specific language
● Locked keys will no longer be available for translation
● Reporting a translation for a translation key can unlock the key
SDK Integration
Supported Platforms
● PHP (>= 5.3)● Ruby on Rails (>= 3.2)● JavaScript● Objective C, iOS (>= 6.2)● Java (work in progress)● Python (work in progress)● .Net, C# (work in progress)
Install Composer
$ cd PROJECT_FOLDER$ curl -s http://getcomposer.org/installer | php
Configure Composer
Create composer.json file with the following:
{ "require": { "tr8n/tr8n-client-sdk": "dev-master" }}
Install Vendor Packages
$ php composer.phar install
Get Application Key & Secret
Sample PHP File <?php require_once(__DIR__ . '/vendor/tr8n/tr8n-client-sdk/library/Tr8n.php'); ?> <?php tr8n_init_client_sdk("https://tr8nhub.com", your_app_key, your_app_secret); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="<?php echo tr8n_current_language()->locale ?>" dir="<?php echo tr8n_current_language()->direction ?>">
<head> <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" /> <?php include(__DIR__ . '/vendor/tr8n/tr8n-client-sdk/library/Tr8n/Includes/Scripts.php'); ?></head><body> <?php tre("Hello World") ?></body></html><?php tr8n_complete_request() ?>
Translation Markup Language TML™
Translation Markup Language
● Simple and extensible syntax
● Platform and technology independent
● Improves code readability
● Code completion support is coming...
TML Modes
● Simple TML ○ Used by beginner and intermediate translators
● Advanced TML ○ Available through TML extensions ○ Used by developers and advanced translators
<?php echo tr(“Hello World”) ?>
TML
● $label - required string
● $description - optional context of the label
● $tokens - optional hash of tokens; required if tokens are used in the label
● $options - optional array of options
<?php echo tr($label, $description = "", $tokens = array(), $options = array()) ?>
Translation Method
Alternatives <?php echo tr($label, $tokens = array(), $options = array()) ?>
<?php echo tr(array(“label” => “”, “description” => “”, “tokens” => array(), “options” => array())
) ?>
Additional Methods
● tre(...) - automatically echos the result
● trl(...) - disables inline translations; used for options and alt tags
● trle(...) - same as trl without inline translations
<img src=”picture.png” alt=”<?php trle(‘Profile photo’) ?>”>
Label Description
Are these the same?
<?php tre(“Home”, “Place of residence”) ?>
vs
<?php tre(“Home”, “Main page of the site”) ?>
Label Description
● The description is not mandatory, but it should be used when the label is ambiguous
● Tr8n uses label and description together to create a unique key for each translation key
● The description serves a hint to the translators for the context in which the key was used
TML Tokens
TML Tokens
● Dynamic data substitution● Minimize the number of translation keys● Maximize translation key reuse● Decorate translation key elements● Nest translations (but don’t take them
out of context)
TML Token Types
● Data Tokens○ Curly brackets with a name of a token○ {token_name:type::case}○ Supports extensions (Pipes and Methods tokens)
● Decoration Tokens○ Square brackets with a name of a decoration○ [token_name] value_to_be_decorated [/token_name]○ [token_name: value_to_be_decorated]
TML
DEMO TIME !!!
Other Features
Blocks○ Provide a mechanism to specify options to all nested
translation calls○ Can be nested
Sources○ Allow grouping of translation keys per page, include,
or any structure
Components○ Groups of sources assigned to translators for specific
languages
Caching
Tr8n Caching
● Tr8n API is only used in translation mode and in a cache warm-up mode
● In all other cases all data is served from local cache
● SDKs have a mechanism to invalidate and rebuild cache
Supported Cache Adapters
● Files (JSON or YAML)● APC● Memcached (Memcache)● Redis● CHDB
● Easy to add others
Resources● Tr8nHub service
○ https://tr8nhub.com● Documentation
○ http://wiki.tr8nhub.com● Blog
○ http://blog.tr8nhub.com● SDK Source Code
○ https://github.com/tr8n/tr8n_php_clientsdk● PHP Sample Service
○ http://php.tr8nhub.com
My Email: [email protected]: @tr8nhub @theiceberk
Q & A