diff --git a/application/Espo/Core/Utils/I18n.php b/application/Espo/Core/Utils/I18n.php index bc4a54dd6f..f5e3d2ac6d 100644 --- a/application/Espo/Core/Utils/I18n.php +++ b/application/Espo/Core/Utils/I18n.php @@ -1,4 +1,4 @@ - 'English (United States)',) + * Result will be array('en_US' => 'English (United States)', 'de_DE' => 'de_DE',) + * @return string | array + */ + public function translate($label, $category = 'labels', $scope = 'Global', $requiredOptions = null) { if (is_array($label)) { $translated = array(); @@ -119,6 +131,16 @@ class I18n } else { $key = $scope.'.'.$category.'.'.$label; $translated = $this->get($key, $label); + + if (is_array($translated) && isset($requiredOptions)) { + + $optionKeys = array_keys($translated); + foreach ($requiredOptions as $option) { + if (!in_array($option, $optionKeys)) { + $translated[$option] = $option; + } + } + } } return $translated; diff --git a/install/core/Installer.php b/install/core/Installer.php index 9d1988b911..63e0eab5cd 100644 --- a/install/core/Installer.php +++ b/install/core/Installer.php @@ -111,12 +111,11 @@ class Installer { $config = $this->app->getContainer()->get('config'); - $languageList = array( - 'options' => $config->get('languageList'), - ); - $translated = $this->translateSetting('language', $languageList); + $languageList = $config->get('languageList'); + + $translated = $this->getI18n()->translate('language', 'options', 'Global', $languageList); - return $translated['options']; + return $translated; } /** @@ -210,6 +209,7 @@ class Installer $entity->set('userName', $userName); $entity->set('password', md5($password)); $entity->set('lastName', 'Administrator'); + $entity->set('isAdmin', '1'); $userId = $this->getEntityManager()->saveEntity($entity); @@ -303,6 +303,10 @@ class Installer } } + if (isset($defaults['language'])) { + $defaults['language']['options'] = $this->getLanguageList(); + } + return $defaults; } diff --git a/tests/Espo/Core/Utils/I18nTest.php b/tests/Espo/Core/Utils/I18nTest.php index 21bd765366..0fd57ef1ce 100644 --- a/tests/Espo/Core/Utils/I18nTest.php +++ b/tests/Espo/Core/Utils/I18nTest.php @@ -99,7 +99,18 @@ class I18nTest extends \PHPUnit_Framework_TestCase 'source' => 'Crm Module', ), ), + 'Global' => + array ( + 'options' => + array ( + 'language' => + array ( + 'en_US' => 'English (United States)', + ) + ), + ), ); + $this->assertEquals($result, $this->reflection->invokeMethod('getData', array())); } @@ -135,6 +146,28 @@ class I18nTest extends \PHPUnit_Framework_TestCase $this->assertEquals($result, $this->object->translate($input, 'fields', 'User')); } + function testTranslateOption() + { + $result = array( + 'en_US' => 'English (United States)', + ); + $this->assertEquals($result, $this->object->translate('language', 'options')); + } + + function testTranslateOptionWithRequiredOptions() + { + $result = array( + 'en_US' => 'English (United States)', + 'de_DE' => 'de_DE', + ); + $requiredOptions = array( + 'en_US', + 'de_DE', + ); + + $this->assertEquals($result, $this->object->translate('language', 'options', 'Global', $requiredOptions)); + } + } diff --git a/tests/testData/Utils/Config/config.php b/tests/testData/Utils/Config/config.php index c2460e7f50..75e3d8b7ab 100644 --- a/tests/testData/Utils/Config/config.php +++ b/tests/testData/Utils/Config/config.php @@ -1,4 +1,24 @@ - diff --git a/tests/testData/Utils/Config/testArray.php b/tests/testData/Utils/Config/testArray.php index a08299cda4..b43cc79273 100644 --- a/tests/testData/Utils/Config/testArray.php +++ b/tests/testData/Utils/Config/testArray.php @@ -1,4 +1,24 @@ - 'Another Wrong Value', diff --git a/tests/testData/Utils/I18n/Espo/Resources/i18n/en_US/Global.json b/tests/testData/Utils/I18n/Espo/Resources/i18n/en_US/Global.json new file mode 100644 index 0000000000..adf1d17515 --- /dev/null +++ b/tests/testData/Utils/I18n/Espo/Resources/i18n/en_US/Global.json @@ -0,0 +1,7 @@ +{ + "options": { + "language": { + "en_US": "English (United States)" + } + } +} \ No newline at end of file diff --git a/tests/testData/Utils/I18n/cache/application/languages/en_GB.php b/tests/testData/Utils/I18n/cache/application/languages/en_GB.php index 286f81fa3c..ba2aa268fc 100644 --- a/tests/testData/Utils/I18n/cache/application/languages/en_GB.php +++ b/tests/testData/Utils/I18n/cache/application/languages/en_GB.php @@ -1,4 +1,24 @@ - diff --git a/tests/testData/Utils/I18n/cache/application/languages/en_US.php b/tests/testData/Utils/I18n/cache/application/languages/en_US.php index 286f81fa3c..3832c5a7c0 100644 --- a/tests/testData/Utils/I18n/cache/application/languages/en_US.php +++ b/tests/testData/Utils/I18n/cache/application/languages/en_US.php @@ -1,6 +1,36 @@ - + array ( + 'options' => + array ( + 'language' => + array ( + 'en_US' => 'English (United States)', + ), + ), + ), 'User' => array ( 'fields' =>