2018-11-09 14:28:46 -06:00
|
|
|
#!/bin/perl -w
|
|
|
|
|
|
|
|
use strict;
|
2020-04-07 18:59:53 -05:00
|
|
|
use File::Basename;
|
|
|
|
|
|
|
|
my $path = dirname(dirname($0)) . "/";
|
2018-11-09 14:28:46 -06:00
|
|
|
|
|
|
|
sub readwhole($) {
|
|
|
|
my ($file) = @_;
|
|
|
|
local $/;
|
|
|
|
open(my $fh, '<', $file) || die "Cannot open $file";
|
|
|
|
return <$fh>;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub insert($) {
|
|
|
|
my ($locale) = @_;
|
2020-04-07 18:59:53 -05:00
|
|
|
my $ui = readwhole($path . "po/ui-$locale.po.json");
|
2018-11-09 14:28:46 -06:00
|
|
|
# Different convention: Change underscore to hyphen.
|
|
|
|
$locale =~ s/_/-/;
|
2020-04-07 18:59:53 -05:00
|
|
|
my $uno = readwhole($path . "l10n/uno/$locale.json");
|
|
|
|
my $locore = readwhole($path . "l10n/locore/$locale.json");
|
2018-11-09 14:28:46 -06:00
|
|
|
# Merge the fields of all three objects into one. The result of
|
|
|
|
# po2json.py starts with "{" not followed by a newline and ends
|
|
|
|
# with a "}" without any final newline. The json files that are in
|
|
|
|
# the repo start with "{\n" and end with "}\n".
|
|
|
|
return substr($ui, 0, length($ui)-1) . ",\n" . substr($uno, 2, length($uno)-4) . ",\n" . substr($locore, 2, length($locore)-3);
|
|
|
|
}
|
|
|
|
|
|
|
|
# The list of locales handled in the JavaScript we output below is
|
|
|
|
# based on a quick glance at the sizes of the translations. Only
|
|
|
|
# translations that are "large enough" (more complete) are included. A
|
|
|
|
# woefully incomplete translation is worse than no translation at all.
|
|
|
|
|
|
|
|
print "\
|
|
|
|
|
|
|
|
var onlylang = window.LANG;
|
|
|
|
var hyphen = onlylang.indexOf('-');
|
|
|
|
if (hyphen > 0) {
|
|
|
|
onlylang = onlylang.substring(0, hyphen);
|
|
|
|
}
|
|
|
|
var underscore = onlylang.indexOf('_');
|
|
|
|
if (underscore > 0) {
|
|
|
|
onlylang = onlylang.substring(0, underscore);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (false) {
|
|
|
|
;
|
2022-04-05 08:18:42 -05:00
|
|
|
} else if (onlylang == 'ar') {
|
|
|
|
window.LOCALIZATIONS = " . insert('ar') . ";
|
2019-12-11 04:46:52 -06:00
|
|
|
} else if (onlylang == 'cs') {
|
|
|
|
window.LOCALIZATIONS = " . insert('cs') . ";
|
2018-11-09 14:28:46 -06:00
|
|
|
} else if (onlylang == 'da') {
|
|
|
|
window.LOCALIZATIONS = " . insert('da') . ";
|
|
|
|
} else if (onlylang == 'de') {
|
|
|
|
window.LOCALIZATIONS = " . insert('de') . ";
|
|
|
|
} else if (onlylang == 'el') {
|
|
|
|
window.LOCALIZATIONS = " . insert('el') . ";
|
2020-07-09 07:55:03 -05:00
|
|
|
} else if (window.LANG == 'en-GB' || window.LANG == 'en_GB') {
|
2018-11-09 14:28:46 -06:00
|
|
|
window.LOCALIZATIONS = " . insert('en_GB') . ";
|
|
|
|
} else if (onlylang == 'es') {
|
|
|
|
window.LOCALIZATIONS = " . insert('es') . ";
|
|
|
|
} else if (onlylang == 'fr') {
|
|
|
|
window.LOCALIZATIONS = " . insert('fr') . ";
|
2022-04-05 08:18:42 -05:00
|
|
|
} else if (onlylang == 'he') {
|
|
|
|
window.LOCALIZATIONS = " . insert('he') . ";
|
2018-11-09 14:28:46 -06:00
|
|
|
} else if (onlylang == 'hu') {
|
|
|
|
window.LOCALIZATIONS = " . insert('hu') . ";
|
|
|
|
} else if (onlylang == 'is') {
|
|
|
|
window.LOCALIZATIONS = " . insert('is') . ";
|
|
|
|
} else if (onlylang == 'it') {
|
|
|
|
window.LOCALIZATIONS = " . insert('it') . ";
|
2019-05-30 04:26:09 -05:00
|
|
|
} else if (onlylang == 'ja') {
|
|
|
|
window.LOCALIZATIONS = " . insert('ja') . ";
|
|
|
|
} else if (onlylang == 'ko') {
|
|
|
|
window.LOCALIZATIONS = " . insert('ko') . ";
|
2018-11-09 14:28:46 -06:00
|
|
|
} else if (onlylang == 'nb') {
|
|
|
|
window.LOCALIZATIONS = " . insert('nb') . ";
|
|
|
|
} else if (onlylang == 'nl') {
|
|
|
|
window.LOCALIZATIONS = " . insert('nl') . ";
|
|
|
|
} else if (onlylang == 'nn') {
|
|
|
|
window.LOCALIZATIONS = " . insert('nn') . ";
|
2019-05-30 04:26:09 -05:00
|
|
|
} else if (onlylang == 'pl') {
|
|
|
|
window.LOCALIZATIONS = " . insert('pl') . ";
|
2020-07-09 07:55:03 -05:00
|
|
|
} else if (window.LANG == 'pt-BR' || window.LANG == 'pt_BR') {
|
2018-11-09 14:28:46 -06:00
|
|
|
window.LOCALIZATIONS = " . insert('pt_BR') . ";
|
|
|
|
} else if (onlylang == 'pt') {
|
|
|
|
window.LOCALIZATIONS = " . insert('pt') . ";
|
|
|
|
} else if (onlylang == 'ru') {
|
|
|
|
window.LOCALIZATIONS = " . insert('ru') . ";
|
|
|
|
} else if (onlylang == 'sk') {
|
|
|
|
window.LOCALIZATIONS = " . insert('sk') . ";
|
2022-04-05 08:18:42 -05:00
|
|
|
} else if (onlylang == 'sl') {
|
|
|
|
window.LOCALIZATIONS = " . insert('sl') . ";
|
2018-11-09 14:28:46 -06:00
|
|
|
} else if (onlylang == 'sv') {
|
|
|
|
window.LOCALIZATIONS = " . insert('sv') . ";
|
|
|
|
} else if (onlylang == 'tr') {
|
|
|
|
window.LOCALIZATIONS = " . insert('tr') . ";
|
|
|
|
} else if (onlylang == 'uk') {
|
|
|
|
window.LOCALIZATIONS = " . insert('uk') . ";
|
2020-07-09 07:55:03 -05:00
|
|
|
} else if (window.LANG == 'zh-CN' || window.LANG == 'zh-Hans-CN' || window.LANG == 'zh_CN' || window.LANG == 'zh_Hans_CN' ) {
|
|
|
|
window.LOCALIZATIONS = " . insert('zh_CN') . ";
|
|
|
|
} else if (window.LANG == 'zh-TW' || window.LANG == 'zh-Hant-TW' || window.LANG == 'zh_TW' || window.LANG == 'zh_Hant_TW') {
|
2018-11-09 14:28:46 -06:00
|
|
|
window.LOCALIZATIONS = " . insert('zh_TW') . ";
|
|
|
|
} else {
|
|
|
|
window.LOCALIZATIONS = {};
|
|
|
|
}
|
|
|
|
";
|