Passed
Push — master ( 2955c9...ee5866 )
by Fran
05:26
created

I18nController::defaultTranslations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
crap 2
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
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

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.

Loading history...
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
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

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.

Loading history...
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");
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 156 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
51
        return $this->render("translations.html.twig", array(
52
            "translations" => $translations,
53
        ));
54
    }
55
}