Add an i18n example.
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class I18n extends Mustache {
|
||||||
|
|
||||||
|
// Variable to be interpolated
|
||||||
|
public $name = 'Bob';
|
||||||
|
|
||||||
|
// Add a {{#__}} lambda for i18n
|
||||||
|
public $__ = array(self, '__trans');
|
||||||
|
|
||||||
|
// A *very* small i18n dictionary :)
|
||||||
|
private $dictionary = array(
|
||||||
|
'Hello.' => 'Hola.',
|
||||||
|
'My name is {{ name }}.' => 'Me llamo {{ name }}.',
|
||||||
|
);
|
||||||
|
|
||||||
|
public function __trans($text) {
|
||||||
|
return isset($this->dictionary[$text]) ? $this->dictionary[$text] : $text;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{{#__}}Hello.{{/__}} {{#__}}My name is {{ name }}.{{/__}}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Hola. Me llamo Bob.
|
||||||
Reference in New Issue
Block a user