This repository has been archived by the owner on May 3, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #638 from ezsystems/ezp-25323_contenttype_name-1.4
EZP-25323: ContentType name and description not showed if it is not translated in eng-GB
- Loading branch information
Showing
77 changed files
with
762 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace EzSystems\PlatformUIBundle\ApplicationConfig\Providers; | ||
|
||
use EzSystems\PlatformUIBundle\ApplicationConfig\Provider; | ||
|
||
/** | ||
* Provides the Locales conversion map from POSIX code to eZ Locale Code. | ||
*/ | ||
class LocalesMap implements Provider | ||
{ | ||
/** @var string */ | ||
private $eZToPosixMap; | ||
|
||
public function __construct($localesMap) | ||
{ | ||
$this->eZToPosixMap = $localesMap; | ||
} | ||
|
||
public function getConfig() | ||
{ | ||
return array_flip($this->eZToPosixMap); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/* | ||
* Copyright (C) eZ Systems AS. All rights reserved. | ||
* For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
YUI.add('ez-translateproperty', function (Y) { | ||
"use strict"; | ||
/** | ||
* Provides the translate property plugin | ||
* | ||
* @module ez-translateproperty | ||
*/ | ||
Y.namespace('eZ'); | ||
|
||
Y.eZ.TranslateProperty = Y.Base.create('translateProperty', Y.Base, [], { | ||
/** | ||
* Find the correct property translation according to browser's | ||
* languages configuration. It basically iterates over the browser's | ||
* languages to find a matching translation, if none matches, it takes | ||
* the first one. | ||
* | ||
* @method translateProperty | ||
* @param {Object} fullLocalesMap the Locales map between POSIX Locales | ||
* (e.g.) fr_FR and Locales used in eZ Platform (e.g. fre-FR) | ||
* @param {Object} property the property to translate as a hash indexed | ||
* by eZ Locale for example: | ||
* | ||
* {'eng-GB': 'potatoes', 'fre-FR': 'pomme de terre'} | ||
* | ||
* @return {String} | ||
*/ | ||
translateProperty: function (fullLocalesMap, property) { | ||
var navigatorLocales = this._getNavigatorPosixLocales(), | ||
localesMap = this._getLocalesMap(fullLocalesMap, property), | ||
matchingPosixLocale; | ||
|
||
Y.Array.some(navigatorLocales, function (posixLocale) { | ||
var prefixLanguage; | ||
|
||
if ( localesMap[posixLocale] ) { | ||
matchingPosixLocale = posixLocale; | ||
return true; | ||
} | ||
if ( posixLocale.indexOf('_') !== -1 ) { | ||
prefixLanguage = posixLocale.split('_')[0] + '_'; | ||
} else { | ||
prefixLanguage = posixLocale + '_'; | ||
} | ||
matchingPosixLocale = this._findPosixLocaleByPrefix( | ||
prefixLanguage, localesMap | ||
); | ||
return !!matchingPosixLocale; | ||
}, this); | ||
|
||
if ( matchingPosixLocale ) { | ||
return property[localesMap[matchingPosixLocale]]; | ||
} | ||
return property[Object.keys(property)[0]]; | ||
}, | ||
|
||
/** | ||
* Returns the POSIX Locale matching the prefix | ||
* | ||
* @private | ||
* @method _findPosixLocaleByPrefix | ||
* @param {String} prefix e.g. 'fr' | ||
* @param {Object} localesMap the locales map for the property | ||
* @param {String} e.g. 'fr_fr' | ||
*/ | ||
_findPosixLocaleByPrefix: function (prefix, localesMap) { | ||
return Y.Array.find(Object.keys(localesMap), function (posixLocale) { | ||
return posixLocale.indexOf(prefix) === 0; | ||
}); | ||
}, | ||
|
||
/** | ||
* Returns an array containing the normalized POSIX locale configured in | ||
* the browser. | ||
* | ||
* @private | ||
* @method _getNavigatorPosixLocales | ||
* @return {Array} e.g. ['fr_fr', 'en_en', 'en'] | ||
*/ | ||
_getNavigatorPosixLocales: function () { | ||
var navigator = this.get('navigator'), | ||
languages = navigator.languages || [navigator.language]; | ||
|
||
return languages.map(function (language) { | ||
return this._normalizeNavigatorLanguage(language); | ||
}, this); | ||
}, | ||
|
||
/** | ||
* Returns an array containing the existing Locale in which the property | ||
* exists. | ||
* | ||
* @private | ||
* @method _getExistingPropertyLanguages | ||
* @param {Object} property | ||
* @param {Array} e.g. ['fre-FR', 'eng-GB'] | ||
*/ | ||
_getExistingPropertyLanguages: function (property) { | ||
return Object.keys(property); | ||
}, | ||
|
||
/** | ||
* Creates a locales map for the languages in which the property exists. | ||
* | ||
* @private | ||
* @method _getLocalesMap | ||
* @param {Object} fullLocalesMap | ||
* @param {Object} property | ||
* @return {Object} an Object containing the locale indexed by | ||
* normalized POSIX locales | ||
*/ | ||
_getLocalesMap: function (fullLocalesMap, property) { | ||
var localesMap = {}, | ||
existingLocales = this._getExistingPropertyLanguages(property); | ||
|
||
Y.Object.each(fullLocalesMap, function (locale, posixLocale) { | ||
if ( existingLocales.indexOf(locale) !== -1 ) { | ||
localesMap[this._normalizeNavigatorLanguage(posixLocale)] = locale; | ||
} | ||
}, this); | ||
return localesMap; | ||
}, | ||
|
||
/** | ||
* Normalizes browser's language | ||
* | ||
* @private | ||
* @method _normalizeNavigatorLanguage | ||
* @param {String} lang the language e.g. 'fr-FR' | ||
* @return {String} | ||
*/ | ||
_normalizeNavigatorLanguage: function (lang) { | ||
return lang.toLowerCase().replace('-', '_'); | ||
}, | ||
|
||
}, { | ||
ATTRS: { | ||
/** | ||
* Holds a reference to the navigator object. | ||
* | ||
* @attribute navigator | ||
* @type {Navigator} | ||
* @readOnly | ||
*/ | ||
navigator: { | ||
value: Y.config.win.navigator, | ||
cloneDefaultValue: false, | ||
readOnly: true, | ||
}, | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.