Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
enh(core): add mechanism to get frontend translation of extensions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kduret authored May 21, 2019
1 parent 6f186b3 commit 6bb4fb4
Show file tree
Hide file tree
Showing 16 changed files with 379 additions and 144 deletions.
18 changes: 0 additions & 18 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,6 @@ function loadDependencyInjector()

$dependencyInjector['path.files_generation'] = _CENTREON_PATH_ . '/filesGeneration/';

// Defines the web service that will transform the translation files into one json file
$dependencyInjector[CentreonI18n::class] = function ($container) {
require_once _CENTREON_PATH_ . '/www/api/class/centreon_i18n.class.php';
$lang = getenv('LANG');
if ($lang === false) {
// Initialize the language translator
$container['translator'];
$lang = getenv('LANG');
}
if (strstr($lang, '.UTF-8') === false) {
$lang .= '.UTF-8';
}
$translationFile = _CENTREON_PATH_ . "www/locale/{$lang}/LC_MESSAGES/messages.ser";
$translation = new CentreonI18n();
$translation->setFilesGenerationPath($translationFile);
return $translation;
};

// Dynamically register service provider
\Centreon\Infrastructure\Provider\AutoloadServiceProvider::register($dependencyInjector);

Expand Down
73 changes: 46 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@babel/preset-react": "^7.0.0",
"clean-webpack-plugin": "^2.0.1",
"css-loader": "^2.1.0",
"expose-loader": "^0.7.5",
"file-loader": "^3.0.1",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.5.0",
Expand All @@ -38,7 +37,7 @@
"dom-serializer": "^0.1.0",
"install": "^0.12.2",
"loaders.css": "^0.1.2",
"moment-timezone": "^0.5.21",
"moment-timezone": "^0.5.25",
"numeral": "^2.0.6",
"query-string": "^5.1.1",
"react": "^16.4.2",
Expand All @@ -58,7 +57,7 @@
"redux-logger": "^3.0.6",
"redux-saga": "^0.16.2",
"redux-thunk": "^2.3.0",
"systemjs": "^3.0.0",
"systemjs": "^3.1.6",
"systemjs-plugin-css": "^0.1.37"
},
"jest": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright 2005-2018 Centreon
* Centreon is developped by : Julien Mathis and Romain Le Merlus under
* Copyright 2005-2019 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
* This program is free software; you can redistribute it and/or modify it under
Expand Down Expand Up @@ -32,54 +32,54 @@
* For more information : contact@centreon.com
*
*/
namespace Centreon\Application\Webservice;

use CentreonRemote\Application\Webservice\CentreonWebServiceAbstract;

/**
* Webservice that allow to retrieve all translations in one json file.
* If the file doesn't exist it will be created at the first reading.
*/
class CentreonI18n extends CentreonWebService
class CentreonI18n extends CentreonWebServiceAbstract
{
/**
* @var string Path where the translation file will be generate.
*/
private $filesGenerationPath;


/**
* Return a table containing all the translations.
* Name of web service object
*
* @return array
* @throws \Exception
* @return string
*/
public function getTranslation(): array
public static function getName(): string
{
if (file_exists($this->filesGenerationPath)) {
$data = unserialize(
file_get_contents($this->filesGenerationPath)
);
return $data;
} else {
throw new \Exception("Translation files does not exists");
}
return 'centreon_i18n';
}

/**
* Retrieves the path where the translation file will be generate.
* Authorize to access to the action
*
* @return string
* @param string $action The action name
* @param \CentreonUser $user The current user
* @param boolean $isInternal If the api is call in internal
*
* @return boolean If the user has access to the action
*/
public function getFilesGenerationPath(): ?string
public function authorize($action, $user, $isInternal = false)
{
return $this->filesGenerationPath;
return true;
}

/**
* Defined the path where the translation file will be generate.
* Return a table containing all the translations.
*
* @param string $filesGenerationPath
* @return array
* @throws \Exception
*/
public function setFilesGenerationPath(string $filesGenerationPath): void
public function getTranslation(): array
{
$this->filesGenerationPath = $filesGenerationPath;
try {
$translation = $this->getDi()['centreon.i18n_service']->getTranslation();
} catch (\Exception $e) {
throw new \Exception("Translation files does not exists");
}

return $translation;
}
}
Loading

0 comments on commit 6bb4fb4

Please sign in to comment.