Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how setup I18n ? #329

Open
historylife opened this issue Oct 1, 2017 · 1 comment
Open

how setup I18n ? #329

historylife opened this issue Oct 1, 2017 · 1 comment

Comments

@historylife
Copy link

class I18n
{
    // Variable to be interpolated

    public $name = 'Bob';
    // Add a {{#__}} lambda for i18n
    public $__ = array(__CLASS__, '__trans');
    // A *very* small i18n dictionary :)
    private static $dictionary = array(
        'Hello.'                 => 'Hola.',
        'My name is {{ name }}.' => 'Me llamo {{ name }}.',
    );
    public static function __trans($text)
    {
        return isset(self::$dictionary[$text]) ? self::$dictionary[$text] : $text;
    }
}

$mustache = new Mustache_Engine( array(
			'loader' => new Mustache_Loader_FilesystemLoader($BASE.'../templates', array('extension' => '.html')),
			'partials_loader' => new Mustache_Loader_FilesystemLoader($BASE.'../templates/partials', array('extension' => '.html')),
			'escape' => function($value) {
				return htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
			},
			'helpers' => array('i18n' => function ($text) {
// What should i do here ?
              }),
			'charset' => 'UTF-8',			
			'strict_callables' => true,
));
@superruzafa
Copy link

superruzafa commented Nov 6, 2017

Please, take a look at my own solution for i18n html pages with Mustache.

https://github.com/superruzafa/visual-scala-reference/blob/master/src/build-index.php#L15

{{# t }}{{ variable }}{{/ t }}

Every variable must be an array whose keys is a two-letter code.

[
  'variable' => [
    'en' => 'English message',
    'es' => 'Spanish message',
    ...
  ]
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants