diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b1001a6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/** diff --git a/includes/settings.example.php b/includes/settings.example.php index 504da57..d38cc74 100644 --- a/includes/settings.example.php +++ b/includes/settings.example.php @@ -21,4 +21,9 @@ $recaptcha_site_key = ''; $recaptcha_secret_key = ''; + // Plurals types per language + $langPlurals['pl'] = array('one', 'few', 'many'); + $langPlurals['es-rMX'] = array('one', 'other'); + $langPlurals['pt-rBR'] = array('one', 'other'); + ?> diff --git a/translation.php b/translation.php index be95c86..1a522bd 100644 --- a/translation.php +++ b/translation.php @@ -84,7 +84,6 @@ $namePos = strpos($line, 'name="') + 6; $stringPos = strPos($line, '>', $namePos) + 1; $name = substr($line, $namePos, strpos($line, '"', $namePos) - $namePos); - //$newValue = stripslashes($_POST[$name]); $newValue = str_replace("\n","\\n",$_POST[$name]); if (trim($newValue) != '') { $outfile .= $indentation . substr($line, 0, $stringPos) . $newValue . substr($line, strrpos($line, '<')) . "\n"; @@ -127,12 +126,41 @@ $outfile .= substr($line, 0, 6) . $newValues[$n] . substr($line, strrpos($line, '<')) . "\n"; $n++; $multiline = ""; + // lines } else if (substr($line, 0, 15) == '') { if ($skipStringArray) { $multiline = ""; continue; } $outfile .= $line . "\n"; + // " . $newValue . "" . "\n"; + } + } + $outfile .= $indentation . "\n"; + } + // ') { + continue; // Already printed as part of the plural } else { if ($multiline != "") { $multiline .= $line; @@ -294,7 +322,26 @@ function parseStrings($file) { $val = substr($line, 6, strrpos($line, '<') - 6); $out[count($out)-1]['values'][] = $val; $multiline = ""; - + + // lines + } else if (substr($line, 0, 8) == '') + 1; + $val = substr($line, $valPos, strrpos($line, '<') - $valPos); + $out[count($out)-1]['values'][$quantity] = $val; + $multiline = ""; + } else if ($multiline != ""){ $multiline .= $line; } @@ -383,27 +430,53 @@ function encodeForInput($in) { $trans = findTranslation($translations, $name); $transtext = $trans['value']; } + showRow($name, $value, $transtext); } else if ($string['type'] == 'stringarray') { $value = implode($arraySeparator, $string['values']); if (isset($translations)) { $trans = findTranslation($translations, $name); $transtext = implode($arraySeparator, $trans['values']); } + showRow($name, $value, $transtext); + } else if ($string['type'] == 'plurals') { + $quantityTypes = getQuantitiesInLang($langPlurals, $lang); + foreach ($quantityTypes as $type) { + $quantityName = $name . "_quantity_" . $type; + if (isset($translations)) { + $trans = findTranslation($translations, $name); + $transtext = $trans['values'][$type]; + } + if ($type == 'one') { + $value = $string['values']['one']; + } else { + $value = $string['values']['other']; + } + showRow($quantityName, $value, $transtext); + } } - //dp($trans); + } + function showRow($name, $value, $transtext) { // Show a table row that has the key, the original English text and a input box with the translation text that is editable echo ' ' . $name . ' ' . str_replace("\\n","
",encodeForHtml($value)) . ' '; - - if (strpos(encodeForInput($value),"\\n") !== FALSE) echo ''; - else echo ''; + + if (strpos(encodeForInput($value),"\\n") !== FALSE) echo ''; + else echo ''; echo ' '; } + + function getQuantitiesInLang($langPlurals, $lang) { + if ($langPlurals[$lang]) { + return $langPlurals[$lang]; + } + // Language is not set up for plurals, fallback to enable all possible plurals + return array('zero', 'one', 'two', 'few', 'many', 'other'); + } echo '