17 use \TYPO3\CMS\Extbase\Utility\LocalizationUtility;
37 'extensionKey' => array(
41 'source' =>
'English label for key1',
42 'target' =>
'English label for key1',
47 'source' =>
'English label for key2',
48 'target' =>
'English label for key2',
53 'source' =>
'English label for key3',
54 'target' =>
'English label for key3',
59 'source' =>
'English label for key4',
60 'target' =>
'English label for key4',
63 'keyWithPlaceholder' => array(
65 'source' =>
'English label with number %d',
66 'target' =>
'English label with number %d',
73 'source' =>
'English label for key1',
74 'target' =>
'Dansk label for key1',
80 'source' =>
'English label for key2',
85 'source' =>
'English label for key3',
91 'source' =>
'English label for key4',
98 'source' =>
'English label for key5',
102 'keyWithPlaceholder' => array(
104 'source' =>
'English label with number %d',
112 'source' =>
'English label for key1',
117 'source' =>
'English label for key2',
118 'target' =>
'Dansk alternative label for key2',
123 'source' =>
'English label for key3',
129 'source' =>
'English label for key4',
135 'source' =>
'English label for key5',
136 'target' =>
'Dansk alternative label for key5',
139 'keyWithPlaceholder' => array(
141 'source' =>
'English label with number %d',
153 $reflectionClass = new \ReflectionClass(
'TYPO3\\CMS\\Extbase\\Utility\\LocalizationUtility');
155 $this->configurationManager = $this->
getAccessibleMock(
'TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager', array(
'getConfiguration'));
156 $property = $reflectionClass->getProperty(
'configurationManager');
157 $property->setAccessible(TRUE);
158 $property->setValue($this->configurationManager);
165 $reflectionClass = new \ReflectionClass(
'TYPO3\\CMS\\Extbase\\Utility\\LocalizationUtility');
167 $property = $reflectionClass->getProperty(
'configurationManager');
168 $property->setAccessible(TRUE);
169 $property->setValue(NULL);
171 $property = $reflectionClass->getProperty(
'LOCAL_LANG');
172 $property->setAccessible(TRUE);
173 $property->setValue(array());
175 $property = $reflectionClass->getProperty(
'languageKey');
176 $property->setAccessible(TRUE);
177 $property->setValue(
'default');
179 $property = $reflectionClass->getProperty(
'alternativeLanguageKeys');
180 $property->setAccessible(TRUE);
181 $property->setValue(array());
189 $reflectionClass = new \ReflectionClass(
'TYPO3\\CMS\\Extbase\\Utility\\LocalizationUtility');
190 $method = $reflectionClass->getMethod(
'flattenTypoScriptLabelArray');
191 $method->setAccessible(TRUE);
196 'key3.subkey1' =>
'subvalue1',
197 'key3.subkey2.subsubkey' =>
'val' 203 'subkey1' =>
'subvalue1',
209 $result = $method->invoke(NULL, $input);
210 $this->assertEquals($expected,
$result);
232 'get translated key' =>
233 array(
'key1', $this->LOCAL_LANG,
'dk',
'Dansk label for key1'),
235 'fallback to English when translation is missing for key' =>
236 array(
'key2', $this->LOCAL_LANG,
'dk',
'English label for key2'),
238 'fallback to English for non existing language' =>
239 array(
'key2', $this->LOCAL_LANG,
'xx',
'English label for key2'),
241 'replace placeholder with argument' =>
242 array(
'keyWithPlaceholder', $this->LOCAL_LANG,
'en',
'English label with number 100', array(), array(100)),
244 'get translated key from primary language' =>
245 array(
'key1', $this->LOCAL_LANG,
'dk',
'Dansk label for key1', array(
'dk_alt')),
247 'fallback to alternative language if translation is missing(llxml)' =>
248 array(
'key2', $this->LOCAL_LANG,
'dk',
'Dansk alternative label for key2', array(
'dk_alt')),
250 'fallback to alternative language if translation is missing(xlif)' =>
251 array(
'key5', $this->LOCAL_LANG,
'dk',
'Dansk alternative label for key5', array(
'dk_alt')),
253 'fallback to English for label not translated in dk and dk_alt(llxml)' =>
254 array(
'key3', $this->LOCAL_LANG,
'dk',
'English label for key3', array(
'dk_alt')),
256 'fallback to English for label not translated in dk and dk_alt(xlif)' =>
257 array(
'key4', $this->LOCAL_LANG,
'dk',
'English label for key4', array(
'dk_alt')),
272 public function translateTest($key, array
$LOCAL_LANG, $languageKey, $expected, array $altLanguageKeys = array(), array $arguments = NULL) {
273 $reflectionClass = new \ReflectionClass(
'TYPO3\\CMS\\Extbase\\Utility\\LocalizationUtility');
275 $property = $reflectionClass->getProperty(
'LOCAL_LANG');
276 $property->setAccessible(TRUE);
277 $property->setValue($LOCAL_LANG);
279 $property = $reflectionClass->getProperty(
'languageKey');
280 $property->setAccessible(TRUE);
281 $property->setValue($languageKey);
283 $property = $reflectionClass->getProperty(
'alternativeLanguageKeys');
284 $property->setAccessible(TRUE);
285 $property->setValue($altLanguageKeys);
295 'override labels with typoscript' => array(
296 'LOCAL_LANG' => array(
297 'extensionKey' => array(
301 'source' =>
'English label for key1',
302 'target' =>
'Dansk label for key1 extensionKey',
307 'source' =>
'English label for key2',
310 'key3.subkey1' => array(
312 'source' =>
'English label for key3',
317 'extensionKey1' => array(
321 'source' =>
'English label for key1',
322 'target' =>
'Dansk label for key1 extensionKey1',
327 'source' =>
'English label for key2',
330 'key3.subkey1' => array(
332 'source' =>
'English label for key3',
338 'typoscript LOCAL_LANG' => array(
339 '_LOCAL_LANG' => array(
341 'key1' =>
'key1 value from TS extensionKey',
343 'subkey1' =>
'key3.subkey1 value from TS extensionKey',
346 'subsubkey' =>
'key3.subkey2.subsubkey value from TS extensionKey' 352 'language key' =>
'dk',
356 'source' =>
'English label for key1',
357 'target' =>
'key1 value from TS extensionKey',
362 'source' =>
'English label for key2',
365 'key3.subkey1' => array(
367 'source' =>
'English label for key3',
368 'target' =>
'key3.subkey1 value from TS extensionKey',
371 'key3.subkey2.subsubkey' => array(
373 'target' =>
'key3.subkey2.subsubkey value from TS extensionKey',
392 public function loadTypoScriptLabels(array $LOCAL_LANG, array $typoScriptLocalLang, $languageKey, array $expected) {
393 $reflectionClass = new \ReflectionClass(
'TYPO3\\CMS\\Extbase\\Utility\\LocalizationUtility');
395 $property = $reflectionClass->getProperty(
'LOCAL_LANG');
396 $property->setAccessible(TRUE);
397 $property->setValue($LOCAL_LANG);
399 $property = $reflectionClass->getProperty(
'languageKey');
400 $property->setAccessible(TRUE);
401 $property->setValue($languageKey);
404 $this->configurationManager->expects($this->at(0))->method(
'getConfiguration')->with($configurationType,
'extensionKey', NULL)->will($this->returnValue($typoScriptLocalLang));
406 $method = $reflectionClass->getMethod(
'loadTypoScriptLabels');
407 $method->setAccessible(TRUE);
408 $method->invoke(NULL,
'extensionKey');
410 $property = $reflectionClass->getProperty(
'LOCAL_LANG');
411 $property->setAccessible(TRUE);
412 $result = $property->getValue();
414 $this->assertEquals($expected,
$result[
'extensionKey'][$languageKey]);
422 $reflectionClass = new \ReflectionClass(
'TYPO3\\CMS\\Extbase\\Utility\\LocalizationUtility');
424 $property = $reflectionClass->getProperty(
'LOCAL_LANG');
425 $property->setAccessible(TRUE);
426 $property->setValue($this->LOCAL_LANG);
428 $property = $reflectionClass->getProperty(
'languageKey');
429 $property->setAccessible(TRUE);
430 $property->setValue(
'dk');
432 $typoScriptLocalLang = array(
433 '_LOCAL_LANG' => array(
441 $this->configurationManager->expects($this->at(0))->method(
'getConfiguration')->with($configurationType,
'extensionKey', NULL)->will($this->returnValue($typoScriptLocalLang));
443 $method = $reflectionClass->getMethod(
'loadTypoScriptLabels');
444 $method->setAccessible(TRUE);
445 $method->invoke(NULL,
'extensionKey');
449 $this->assertEquals(
'',
$result);
$configurationManagerMock
implodeTypoScriptLabelArrayWorks()
const CONFIGURATION_TYPE_FRAMEWORK
translateTest($key, array $LOCAL_LANG, $languageKey, $expected, array $altLanguageKeys=array(), array $arguments=NULL)
translateForEmptyStringKeyWithArgumentsReturnsNull()
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.
loadTypoScriptLabels(array $LOCAL_LANG, array $typoScriptLocalLang, $languageKey, array $expected)
clearLabelWithTypoScript()
loadTypoScriptLabelsProvider()
static translate($key, $extensionName, $arguments=NULL)
translateForEmptyStringKeyReturnsNull()