Add an i18n example.

This commit is contained in:
Justin Hileman
2012-01-03 14:00:12 -08:00
parent 3731898939
commit f77cf3729d
3 changed files with 22 additions and 0 deletions
+20
View File
@@ -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;
}
}
+1
View File
@@ -0,0 +1 @@
{{#__}}Hello.{{/__}} {{#__}}My name is {{ name }}.{{/__}}
+1
View File
@@ -0,0 +1 @@
Hola. Me llamo Bob.