-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLang.php
More file actions
50 lines (44 loc) · 1.67 KB
/
Copy pathLang.php
File metadata and controls
50 lines (44 loc) · 1.67 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace FeatherBB\Core\Interfaces;
use Gettext\Translations;
use Gettext\Translator;
class Lang extends \Statical\BaseProxy
{
private static $domain;
private static $translator;
public static function construct($domain = 'FeatherBB')
{
self::$domain = $domain;
self::$translator = new Translator();
self::$translator->defaultDomain($domain);
self::$translator->register();
}
public static function load($file, $domain = 'FeatherBB', $path = false, $language = false)
{
// Set default path to forum core translations
$path = $path ? $path : ForumEnv::get('FEATHER_ROOT').'featherbb/lang';
// Set default language to current user
if (!$language) {
$language = (!User::get(null)) ? 'English' : User::getPref('language');
}
/**
* Try to locate translation file with the following priority order :
* - As provided in function arguments
* - User language
* - Forum default
* - English (which should always be available)
*/
if (is_readable($path.'/'.$language.'/'.$file.'.mo')) {
$file = $path.'/'.$language.'/'.$file.'.mo';
} elseif (is_readable($path.'/'.ForumSettings::get('language').'/'.$file.'.mo')) {
$file = $path.'/'.ForumSettings::get('language').'/'.$file.'.mo';
} elseif (is_readable($path.'/English/'.$file.'.mo')) {
$file = $path.'/English/'.$file.'.mo';
} else {
return false;
}
self::$translator->loadTranslations(
Translations::fromMoFile($file)->setDomain($domain)
);
}
}