-
Notifications
You must be signed in to change notification settings - Fork 10
/
example-detect.php
35 lines (28 loc) · 1.25 KB
/
example-detect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
// Load autoloader from composer or add the library to another autoloader
require_once __DIR__ . '/../vendor/autoload.php';
use Pkly\I18Next\I18n;
use Pkly\I18Next\Plugin\JsonLoader;
use Pkly\I18Next\Plugin\LanguageDetector;
I18n::get([
'lng' => 'ru', // incorrect language that doesn't have any strings - it'd return keys
'fallbackLng' => null // disabled fallback lng, so that keys will be printed out on failed load
])->useModule(new JsonLoader([
'json_resource_path' => __DIR__ . '/data/{{lng}}/{{ns}}.json'
]))->useModule(new LanguageDetector([
'query' => \Pkly\I18Next\Plugin\Detector\Query::class
], [
'lookupQuery' => 'i18n_lng'
]))->init();
echo "Reading 'key' from file - " . I18n::get()->t('key') . "\n";
// Outputs "key"
echo "Reading 'deep.key' from file - " . I18n::get()->t('deep.key') . "\n";
// Outputs "deep.key"
// at some point there was a get parameter called i18n_lng
$_GET['i18n_lng'] = 'en';
// detect language
I18n::get()->changeLanguage('');
echo "Reading 'key' from file - " . I18n::get()->t('key') . "\n";
// Outputs "Translation from file"
echo "Reading 'deep.key' from file - " . I18n::get()->t('deep.key') . "\n";
// Outputs "Translation from deeper into file"