1
|
|
|
<?php |
2
|
|
|
namespace PSFS\controller; |
3
|
|
|
|
4
|
|
|
use PSFS\base\config\Config; |
5
|
|
|
use PSFS\controller\base\Admin; |
6
|
|
|
use PSFS\Services\GeneratorService; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class I18nController |
10
|
|
|
* @package PSFS\controller |
11
|
|
|
*/ |
12
|
|
|
class I18nController extends Admin |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @GET |
17
|
|
|
* @route /admin/translations |
18
|
|
|
* @return string |
|
|
|
|
19
|
|
|
*/ |
20
|
|
|
public function defaultTranslations() |
21
|
|
|
{ |
22
|
|
|
return $this->getTranslations(Config::getInstance()->get('default_language')); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Method that regenerates the translations |
27
|
|
|
* @GET |
28
|
|
|
* @param $locale string |
29
|
|
|
* @route /admin/translations/{locale} |
30
|
|
|
* @visible false |
31
|
|
|
* @return string HTML |
|
|
|
|
32
|
|
|
*/ |
33
|
|
|
public function getTranslations($locale) |
34
|
|
|
{ |
35
|
|
|
//Default locale |
36
|
|
|
if (null === $locale) $locale = $this->config->get("default_language"); |
37
|
|
|
|
38
|
|
|
//Generating the templates translations |
39
|
|
|
$translations = $this->tpl->regenerateTemplates(); |
40
|
|
|
|
41
|
|
|
$locale_path = realpath(BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
42
|
|
|
$locale_path .= DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR; |
43
|
|
|
|
44
|
|
|
//xgettext localizations |
45
|
|
|
$translations = array_merge($translations, GeneratorService::findTranslations(SOURCE_DIR, $locale)); |
46
|
|
|
$translations = array_merge($translations, GeneratorService::findTranslations(CORE_DIR, $locale)); |
47
|
|
|
$translations = array_merge($translations, GeneratorService::findTranslations(CACHE_DIR, $locale)); |
48
|
|
|
|
49
|
|
|
$translations[] = "msgfmt {$locale_path}translations.po -o {$locale_path}translations.mo"; |
50
|
|
|
$translations[] = shell_exec("export PATH=\$PATH:/opt/local/bin:/bin:/sbin; msgfmt {$locale_path}translations.po -o {$locale_path}translations.mo"); |
|
|
|
|
51
|
|
|
return $this->render("translations.html.twig", array( |
52
|
|
|
"translations" => $translations, |
53
|
|
|
)); |
54
|
|
|
} |
55
|
|
|
} |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.