'users_social_connected' => ':socialAccount account was successfully attached to your profile.',
'users_social_disconnected' => ':socialAccount account was successfully disconnected from your profile.',
- // Since these labels are already localized this array does not need to be
- // translated in the language-specific files.
- // DELETE BELOW IF COPIED FROM EN
- ///////////////////////////////////
+ //! Since these labels are already localized this array does not need to be
+ //! translated in the language-specific files.
+ //! DELETE BELOW IF COPIED FROM EN
+ //!////////////////////////////////
'language_select' => [
'en' => 'English',
'ar' => 'العربية',
'zh_CN' => '简体中文',
'zh_TW' => '繁體中文'
]
- ///////////////////////////////////
+ //!////////////////////////////////
];
$lang = formatLocale($args[0]);
$fileName = explode('.', $args[1])[0];
-$filesNames = [$fileName];
+$fileNames = [$fileName];
if ($fileName === '--all') {
$fileNames = getTranslationFileNames();
}
// Start formatted content
$formatted = [];
$mode = 'header';
+ $skipArray = false;
$arrayKeys = [];
- foreach($enLines as $index => $line) {
+ foreach ($enLines as $index => $line) {
$trimLine = trim($line);
if ($mode === 'header') {
$formatted[$index] = $line;
if ($mode === 'body') {
$matches = [];
+ $arrayEndMatch = preg_match('/]\s*,\s*$/', $trimLine);
+
+ if ($skipArray) {
+ if ($arrayEndMatch) $skipArray = false;
+ continue;
+ }
+
+ // Comment to ignore
+ if (strpos($trimLine, '//!') === 0) {
+ $formatted[$index] = "";
+ continue;
+ }
// Comment
if (strpos($trimLine, '//') === 0) {
// Arrays
$arrayStartMatch = preg_match('/^\'(.*)\'\s+?=>\s+?\[(\],)?\s*?$/', $trimLine, $matches);
- $arrayEndMatch = preg_match('/]\s*,\s*$/', $trimLine);
+
$indent = count($arrayKeys) + 1;
if ($arrayStartMatch === 1) {
+ if ($fileName === 'settings' && $matches[1] === 'language_select') {
+ $skipArray = true;
+ continue;
+ }
$arrayKeys[] = $matches[1];
$formatted[$index] = str_repeat(" ", $indent * 4) . str_pad("'{$matches[1]}'", $longestKeyLength) . "=> [";
if ($arrayEndMatch !== 1) continue;
}
// Translation
- $translationMatch = preg_match('/^\'(.*)\'\s+?=>\s+?\'(.*)?\'.+?$/', $trimLine, $matches);
+ $translationMatch = preg_match('/^\'(.*)\'\s+?=>\s+?[\'"](.*)?[\'"].+?$/', $trimLine, $matches);
if ($translationMatch === 1) {
$key = $matches[1];
$keys = array_merge($arrayKeys, [$key]);
* @return string
*/
function formatTranslationLine(string $key, string $value, int $indent = 1, int $keyPad = 1) : string {
- $escapedValue = str_replace("'", "\\'", $value);
- return str_repeat(" ", $indent * 4) . str_pad("'{$key}'", $keyPad, ' ') ."=> '{$escapedValue}',";
+ $start = str_repeat(" ", $indent * 4) . str_pad("'{$key}'", $keyPad, ' ');
+ if (strpos($value, "\n") !== false) {
+ $escapedValue = '"' . str_replace("\n", '\n', $value) . '"';
+ $escapedValue = '"' . str_replace('"', '\"', $escapedValue) . '"';
+ } else {
+ $escapedValue = "'" . str_replace("'", "\\'", $value) . "'";
+ }
+ return "{$start} => {$escapedValue},";
}
/**
$keyLen = strlen($key);
$top = max($top, $keyLen);
}
- return $top + 3;
+ return min(35, $top + 2);
}
/**