fix languages problem

This commit is contained in:
Taras Machyshyn
2014-03-12 13:23:50 +02:00
parent 73605899fb
commit 7cd014f764
8 changed files with 167 additions and 11 deletions
+24 -2
View File
@@ -1,4 +1,4 @@
<?php
<?php
/************************************************************************
* This file is part of EspoCRM.
*
@@ -106,7 +106,19 @@ class I18n
return $langCacheFile;
}
public function translate($label, $category = 'labels', $scope = 'Global')
/**
* Translate label/labels
*
* @param string | array $label name of label
* @param string $category
* @param string $scope
* @param array $requiredOptions List of required options.
* Ex., $requiredOptions = array('en_US', 'de_DE')
* "language" option has only array('en_US' => '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;
+9 -5
View File
@@ -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;
}
+33
View File
@@ -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));
}
}
+21 -1
View File
@@ -1,4 +1,24 @@
<?php
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: http://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
************************************************************************/
return array (
'database' =>
+21 -1
View File
@@ -1,4 +1,24 @@
<?php
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: http://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
************************************************************************/
return array (
'testOption' => 'Another Wrong Value',
@@ -0,0 +1,7 @@
{
"options": {
"language": {
"en_US": "English (United States)"
}
}
}
@@ -1,4 +1,24 @@
<?php
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: http://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
************************************************************************/
return array (
'User' =>
@@ -1,6 +1,36 @@
<?php
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
* Website: http://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
************************************************************************/
return array (
'Global' =>
array (
'options' =>
array (
'language' =>
array (
'en_US' => 'English (United States)',
),
),
),
'User' =>
array (
'fields' =>