Tr8n for php - Michael Berkovich

46
Tr8n for PHP Crowdsourced Translations Presented by Michael Berkovich [email protected] https://github.com/tr8n/tr8n_php_clientsdk

description

 

Transcript of Tr8n for php - Michael Berkovich

Page 1: Tr8n for php - Michael Berkovich

Tr8n for PHPCrowdsourced Translations

Presented by Michael [email protected]

https://github.com/tr8n/tr8n_php_clientsdk

Page 2: Tr8n for php - Michael Berkovich

About Me

● Software Engineer at Digital Evolution, US Interactive, SOA Software, Geni, Yammer

● Creator of Tr8n translation framework

● Founder and CTO at Tr8nHub.com

Page 3: Tr8n for php - Michael Berkovich

What is Tr8n?

Tr8n = Tr[anslatio]n

pronounced “tr - 8 - n”

Translation framework, platform, technology.

Page 4: Tr8n for php - Michael Berkovich

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

Page 5: Tr8n for php - Michael Berkovich

Tr8n Core Features

● Translation Markup Language (TML)

● Rules Engine with Centralized Repository

● Shared Translation Memory (TM)

Page 6: Tr8n for php - Michael Berkovich

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

Page 7: Tr8n for php - Michael Berkovich

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

Page 8: Tr8n for php - Michael Berkovich

Tr8n SDKs

● API Client

● Rules Engine + TML

● Cache Adapters

Page 9: Tr8n for php - Michael Berkovich

Tr8nHub Platform

● Translation Management● User Interface and Widgets● Shared Translation Memory● Translator Tools● Workflows, etc...

Page 10: Tr8n for php - Michael Berkovich

Translation Overview

Page 11: Tr8n for php - Michael Berkovich

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

Page 12: Tr8n for php - Michael Berkovich

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

Page 13: Tr8n for php - Michael Berkovich

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

Page 14: Tr8n for php - Michael Berkovich

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

Page 15: Tr8n for php - Michael Berkovich

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

Page 16: Tr8n for php - Michael Berkovich

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

Page 17: Tr8n for php - Michael Berkovich

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

Page 18: Tr8n for php - Michael Berkovich

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

Page 19: Tr8n for php - Michael Berkovich

Managers

● Translators can be promoted to managers

● Managers get higher voting power

● Managers can configure application setting and language rules

Page 20: Tr8n for php - Michael Berkovich

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

Page 21: Tr8n for php - Michael Berkovich

SDK Integration

Page 22: Tr8n for php - Michael Berkovich

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)

Page 23: Tr8n for php - Michael Berkovich

Install Composer

$ cd PROJECT_FOLDER$ curl -s http://getcomposer.org/installer | php

Page 24: Tr8n for php - Michael Berkovich

Configure Composer

Create composer.json file with the following:

{ "require": { "tr8n/tr8n-client-sdk": "dev-master" }}

Page 25: Tr8n for php - Michael Berkovich

Install Vendor Packages

$ php composer.phar install

Page 26: Tr8n for php - Michael Berkovich

Get Application Key & Secret

Page 27: Tr8n for php - Michael Berkovich

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() ?>

Page 28: Tr8n for php - Michael Berkovich

Translation Markup Language TML™

Page 29: Tr8n for php - Michael Berkovich

Translation Markup Language

● Simple and extensible syntax

● Platform and technology independent

● Improves code readability

● Code completion support is coming...

Page 30: Tr8n for php - Michael Berkovich

TML Modes

● Simple TML ○ Used by beginner and intermediate translators

● Advanced TML ○ Available through TML extensions ○ Used by developers and advanced translators

Page 31: Tr8n for php - Michael Berkovich

<?php echo tr(“Hello World”) ?>

TML

Page 32: Tr8n for php - Michael Berkovich

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

Page 33: Tr8n for php - Michael Berkovich

Alternatives <?php echo tr($label, $tokens = array(), $options = array()) ?>

<?php echo tr(array(“label” => “”, “description” => “”, “tokens” => array(), “options” => array())

) ?>

Page 34: Tr8n for php - Michael Berkovich

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’) ?>”>

Page 35: Tr8n for php - Michael Berkovich

Label Description

Are these the same?

<?php tre(“Home”, “Place of residence”) ?>

vs

<?php tre(“Home”, “Main page of the site”) ?>

Page 36: Tr8n for php - Michael Berkovich

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

Page 37: Tr8n for php - Michael Berkovich

TML Tokens

Page 38: Tr8n for php - Michael Berkovich

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)

Page 39: Tr8n for php - Michael Berkovich

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]

Page 40: Tr8n for php - Michael Berkovich

TML

DEMO TIME !!!

Page 41: Tr8n for php - Michael Berkovich

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

Page 42: Tr8n for php - Michael Berkovich

Caching

Page 43: Tr8n for php - Michael Berkovich

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

Page 44: Tr8n for php - Michael Berkovich

Supported Cache Adapters

● Files (JSON or YAML)● APC● Memcached (Memcache)● Redis● CHDB

● Easy to add others

Page 45: Tr8n for php - Michael Berkovich

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

Page 46: Tr8n for php - Michael Berkovich

Q & A