|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PSFS\controller; |
|
4
|
|
|
|
|
5
|
|
|
use PSFS\base\config\Config; |
|
6
|
|
|
use PSFS\base\types\helpers\I18nHelper; |
|
7
|
|
|
use PSFS\controller\base\Admin; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class I18nController |
|
11
|
|
|
* @package PSFS\controller |
|
12
|
|
|
*/ |
|
13
|
|
|
class I18nController extends Admin |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @GET |
|
18
|
|
|
* @route /admin/translations |
|
19
|
|
|
* @icon fa-language |
|
20
|
|
|
* @label Generador de locales |
|
21
|
|
|
* @return string |
|
22
|
|
|
*/ |
|
23
|
|
|
public function defaultTranslations() |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->getTranslations(Config::getParam('default.language', 'es_ES')); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Method that regenerates the translations |
|
30
|
|
|
* @GET |
|
31
|
|
|
* @param $locale string |
|
32
|
|
|
* @route /admin/translations/{locale} |
|
33
|
|
|
* @label Generador de locales |
|
34
|
|
|
* @visible false |
|
35
|
|
|
* @return string HTML |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getTranslations($locale) |
|
38
|
|
|
{ |
|
39
|
|
|
//Default locale |
|
40
|
|
|
if (null === $locale) { |
|
41
|
|
|
$locale = Config::getParam('default.language', 'es_ES'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
//Generating the templates translations |
|
45
|
|
|
$translations = $this->tpl->regenerateTemplates(); |
|
46
|
|
|
|
|
47
|
|
|
$localePath = realpath(BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
48
|
|
|
$localePath .= DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR; |
|
49
|
|
|
|
|
50
|
|
|
//xgettext localizations |
|
51
|
|
|
$translations = array_merge($translations, I18nHelper::findTranslations(SOURCE_DIR, $locale)); |
|
52
|
|
|
$translations = array_merge($translations, I18nHelper::findTranslations(CORE_DIR, $locale)); |
|
53
|
|
|
$translations = array_merge($translations, I18nHelper::findTranslations(CACHE_DIR, $locale)); |
|
54
|
|
|
|
|
55
|
|
|
$translations[] = "msgfmt {$localePath}translations.po -o {$localePath}translations.mo"; |
|
56
|
|
|
$translations[] = shell_exec('export PATH=\$PATH:/opt/local/bin:/bin:/sbin; msgfmt ' . $localePath . 'translations.po -o ' . $localePath . 'translations.mo'); |
|
57
|
|
|
return $this->render('translations.html.twig', array( |
|
58
|
|
|
'translations' => $translations, |
|
59
|
|
|
)); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|