Skip to content

Language

StefansArya edited this page Aug 26, 2019 · 6 revisions

You may need to import this feature on top of your code.

use \Scarlets\Library\Language;

The default language are configured on /config/app.php.
And the languages files are located on /resources/lang/.

get

Language::get($key, $values = [], $languageID='');
Language::$default = 'en';

// Example
$text = Language::get('time.current_date', ['date'=>date('d M Y')]);

This feature also available when you serving using Serve::view.

<div class="my-view-template">
  <span class="description">
    <?= $lang::get('time.current_date', ['date'=>date('d M Y')], 'en') ?>
  </span>
</div>

I recommend you to turn on PHP's opcache feature to avoid reparsing the language file, this method is better than using JSON as language file. But if you want to convert/extract your language from the PHP script, you can encode the PHP's array from Console like below.

$json = json_encode(Language::load('en'));

// Or only load single language file '/resources/lang/en/time.php'
Language::load('en', 'time');

You could also create a language server for ScarletsFrame's sf.language by building your custom API.

Clone this wiki locally