Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#4779 Move to using XLIFF files for translation (WIP) #4801

Closed
wants to merge 8 commits into from
  •  
  •  
  •  
128 changes: 0 additions & 128 deletions classes/file/EditableLocaleFile.inc.php

This file was deleted.

17 changes: 6 additions & 11 deletions classes/i18n/LocaleFile.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,13 @@ function translate($key, $params = array(), $locale = null) {
*/
static function &load($filename) {
$localeData = array();

// Reload localization XML file
$xmlDao = new XMLDAO();
$data = $xmlDao->parseStruct($filename, array('message'));

// Build array with ($key => $string)
if (isset($data['message'])) {
foreach ($data['message'] as $messageData) {
$localeData[$messageData['attributes']['key']] = $messageData['value'];
}
$translations = Gettext\Translations::fromXliffFile($filename, ['unitid_as_id' => true]);
foreach ($translations as $translation) {
$localeKey = $translation->getId();
// Decode '-' (allowed in XLIFF unit IDs) into '.' (not allowed)
$localeKey = str_replace('-', '.', $localeKey);
if ($localeKey) $localeData[$localeKey] = $translation->getTranslation();
}

return $localeData;
}

Expand Down
26 changes: 13 additions & 13 deletions classes/i18n/PKPLocale.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static function initialize($request) {
}
}

AppLocale::registerLocaleFile($locale, "lib/pkp/locale/$locale/common.xml");
AppLocale::registerLocaleFile($locale, "lib/pkp/locale/$locale/common.xlf");

// Set site time zone
// Starting from PHP 5.3.0 PHP will throw an E_WARNING if the default
Expand Down Expand Up @@ -185,18 +185,18 @@ static function makeComponentMap($locale) {
$baseDir = "lib/pkp/locale/$locale/";

return array(
LOCALE_COMPONENT_PKP_COMMON => $baseDir . 'common.xml',
LOCALE_COMPONENT_PKP_ADMIN => $baseDir . 'admin.xml',
LOCALE_COMPONENT_PKP_INSTALLER => $baseDir . 'installer.xml',
LOCALE_COMPONENT_PKP_MANAGER => $baseDir . 'manager.xml',
LOCALE_COMPONENT_PKP_READER => $baseDir . 'reader.xml',
LOCALE_COMPONENT_PKP_SUBMISSION => $baseDir . 'submission.xml',
LOCALE_COMPONENT_PKP_EDITOR => $baseDir . 'editor.xml',
LOCALE_COMPONENT_PKP_REVIEWER => $baseDir . 'reviewer.xml',
LOCALE_COMPONENT_PKP_USER => $baseDir . 'user.xml',
LOCALE_COMPONENT_PKP_GRID => $baseDir . 'grid.xml',
LOCALE_COMPONENT_PKP_DEFAULT => $baseDir . 'default.xml',
LOCALE_COMPONENT_PKP_API => $baseDir . 'api.xml',
LOCALE_COMPONENT_PKP_COMMON => $baseDir . 'common.xlf',
LOCALE_COMPONENT_PKP_ADMIN => $baseDir . 'admin.xlf',
LOCALE_COMPONENT_PKP_INSTALLER => $baseDir . 'installer.xlf',
LOCALE_COMPONENT_PKP_MANAGER => $baseDir . 'manager.xlf',
LOCALE_COMPONENT_PKP_READER => $baseDir . 'reader.xlf',
LOCALE_COMPONENT_PKP_SUBMISSION => $baseDir . 'submission.xlf',
LOCALE_COMPONENT_PKP_EDITOR => $baseDir . 'editor.xlf',
LOCALE_COMPONENT_PKP_REVIEWER => $baseDir . 'reviewer.xlf',
LOCALE_COMPONENT_PKP_USER => $baseDir . 'user.xlf',
LOCALE_COMPONENT_PKP_GRID => $baseDir . 'grid.xlf',
LOCALE_COMPONENT_PKP_DEFAULT => $baseDir . 'default.xlf',
LOCALE_COMPONENT_PKP_API => $baseDir . 'api.xlf',
);
}

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"illuminate/validation": "^5.5.41",
"firebase/php-jwt": "5.*",
"danielstjules/stringy": "3.*",
"adodb/adodb-php": "dev-v5.20.14-mods"
"adodb/adodb-php": "dev-v5.20.14-mods",
"gettext/gettext": "^4.6.2"
},
"require-dev": {
"facebook/webdriver": "~1.6",
Expand Down
Loading