Merge branch 'v2.0'

This commit is contained in:
Yadd 2021-04-07 15:23:17 +02:00
commit fca479f675
10 changed files with 51 additions and 32 deletions

View File

@ -1211,4 +1211,4 @@
"yubikey2fUrl":"خدمة أل يو أر ل", "yubikey2fUrl":"خدمة أل يو أر ل",
"yubikey2fUserCanRemoveKey":"Allow user to remove Yubikey", "yubikey2fUserCanRemoveKey":"Allow user to remove Yubikey",
"zeroConfExplanations":"لا يحتوي الخادم على إعدادات. استخدام قالب لحفظ الأول" "zeroConfExplanations":"لا يحتوي الخادم على إعدادات. استخدام قالب لحفظ الأول"
} }

View File

@ -1211,4 +1211,4 @@
"yubikey2fUrl":"Service URL", "yubikey2fUrl":"Service URL",
"yubikey2fUserCanRemoveKey":"Allow user to remove Yubikey", "yubikey2fUserCanRemoveKey":"Allow user to remove Yubikey",
"zeroConfExplanations":"Server has no configuration. Use template to save the first." "zeroConfExplanations":"Server has no configuration. Use template to save the first."
} }

View File

@ -1211,4 +1211,4 @@
"yubikey2fUrl":"Service URL", "yubikey2fUrl":"Service URL",
"yubikey2fUserCanRemoveKey":"Allow user to remove Yubikey", "yubikey2fUserCanRemoveKey":"Allow user to remove Yubikey",
"zeroConfExplanations":"Server has no configuration. Use template to save the first." "zeroConfExplanations":"Server has no configuration. Use template to save the first."
} }

View File

@ -1211,4 +1211,4 @@
"yubikey2fUrl":"URL del servizio", "yubikey2fUrl":"URL del servizio",
"yubikey2fUserCanRemoveKey":"Autorizza l'utente a rimuovere la Yubikey", "yubikey2fUserCanRemoveKey":"Autorizza l'utente a rimuovere la Yubikey",
"zeroConfExplanations":"Il server non ha alcuna configurazione. Utilizza il modello per salvare il primo." "zeroConfExplanations":"Il server non ha alcuna configurazione. Utilizza il modello per salvare il primo."
} }

View File

@ -1211,4 +1211,4 @@
"yubikey2fUrl":"URL usługi", "yubikey2fUrl":"URL usługi",
"yubikey2fUserCanRemoveKey":"Pozwól użytkownikowi usunąć Yubikey", "yubikey2fUserCanRemoveKey":"Pozwól użytkownikowi usunąć Yubikey",
"zeroConfExplanations":"Serwer nie ma konfiguracji. Użyj szablonu, aby zapisać pierwszy." "zeroConfExplanations":"Serwer nie ma konfiguracji. Użyj szablonu, aby zapisać pierwszy."
} }

View File

@ -1211,4 +1211,4 @@
"yubikey2fUrl":"Servis URL'si", "yubikey2fUrl":"Servis URL'si",
"yubikey2fUserCanRemoveKey":"Yubikey'i kaldırmak için kullanıcıya izin ver", "yubikey2fUserCanRemoveKey":"Yubikey'i kaldırmak için kullanıcıya izin ver",
"zeroConfExplanations":"Sunucunun yapılandırması yok. Şimdi bir tane kaydetmek için şablonu kullanın." "zeroConfExplanations":"Sunucunun yapılandırması yok. Şimdi bir tane kaydetmek için şablonu kullanın."
} }

View File

@ -1211,4 +1211,4 @@
"yubikey2fUrl":"Dịch vụ URL", "yubikey2fUrl":"Dịch vụ URL",
"yubikey2fUserCanRemoveKey":"Allow user to remove Yubikey", "yubikey2fUserCanRemoveKey":"Allow user to remove Yubikey",
"zeroConfExplanations":"Máy chủ không có cấu hình. Sử dụng mẫu để lưu đầu tiên. " "zeroConfExplanations":"Máy chủ không có cấu hình. Sử dụng mẫu để lưu đầu tiên. "
} }

View File

@ -1211,4 +1211,4 @@
"yubikey2fUrl":"Service URL", "yubikey2fUrl":"Service URL",
"yubikey2fUserCanRemoveKey":"Allow user to remove Yubikey", "yubikey2fUserCanRemoveKey":"Allow user to remove Yubikey",
"zeroConfExplanations":"Server has no configuration. Use template to save the first." "zeroConfExplanations":"Server has no configuration. Use template to save the first."
} }

View File

@ -1211,4 +1211,4 @@
"yubikey2fUrl":"服務 URL", "yubikey2fUrl":"服務 URL",
"yubikey2fUserCanRemoveKey":"允許使用者移除 Yubikey", "yubikey2fUserCanRemoveKey":"允許使用者移除 Yubikey",
"zeroConfExplanations":"伺服器未設定。使用飯本來儲存第一個。" "zeroConfExplanations":"伺服器未設定。使用飯本來儲存第一個。"
} }

View File

@ -3,21 +3,37 @@
use strict; use strict;
use JSON; use JSON;
use Getopt::Long; use Getopt::Long;
my ( $portal, $modify, $help, $delete ); my ( $portal, $modify, $help, $delete, $reorder );
my $json = my $json =
JSON->new->utf8->pretty()->canonical()->space_before(0)->space_after(0); JSON->new->utf8->pretty()->canonical()->space_before(0)->space_after(0);
GetOptions( GetOptions(
"portal|p" => \$portal, "portal|p" => \$portal,
"modify|m" => \$modify, "modify|m" => \$modify,
"delete|d" => \$delete, "delete|d" => \$delete,
"help|h" => \$help, "reorder|r" => \$reorder,
"help|h" => \$help,
); );
usage() if $help or !@ARGV; usage() if $help or ( !@ARGV and !$reorder );
my $key = shift @ARGV or usage(); my $key = shift @ARGV;
my $enText = shift @ARGV or $delete or usage(); my $enText = shift @ARGV;
my $frText = shift(@ARGV) || $enText; my $frText = shift(@ARGV) || $enText;
# Check args
usage() if $delete and $modify;
if ($key) {
usage() if $reorder;
if ($delete) {
usage() if $enText;
}
else {
usage() unless $enText;
}
}
else {
usage() unless $reorder;
}
# Main # Main
my $wdir = my $wdir =
'lemonldap-ng-' 'lemonldap-ng-'
@ -36,19 +52,19 @@ for my $lang (@langs) {
close $file; close $file;
} }
my $jsonObj = $json->decode($content); my $jsonObj = $json->decode($content);
if ( !$jsonObj->{$key} and $delete ) { if ($key) {
print STDERR "$key does not exist, aborting deletion\n"; if ( $jsonObj->{$key} xor( $delete or $modify ) ) {
usage(); print STDERR ( $jsonObj->{$key}
} ? "key already exists\n"
elsif ( $jsonObj->{$key} and $modify ) { : "key doesn't exit\n" );
print STDERR "$key already exists, aborting\n"; usage();
usage(); }
} if ($delete) {
if ($delete) { delete $jsonObj->{$key};
delete $jsonObj->{$key}; }
} else {
else { $jsonObj->{$key} = ( $lang eq 'fr.json' ? $frText : $enText );
$jsonObj->{$key} = ( $lang eq 'fr.json' ? $frText : $enText ); }
} }
$content = $json->encode($jsonObj); $content = $json->encode($jsonObj);
$content =~ s/\n\s+/\n/sg; $content =~ s/\n\s+/\n/sg;
@ -65,8 +81,11 @@ Usage:
$0 <option> key enText <frText> $0 <option> key enText <frText>
Options: Options:
--portal -p: add entry in portal translation instead of manager --portal -p: add entry in portal translation instead of manager
--modify -m: modify an existing entry --modify -m: modify an existing entry
--delete -d: delete an existing key
--reorder -r: reorder files
--help -h: display this
EOT EOT
exit( $help ? 0 : 1 ); exit( $help ? 0 : 1 );
} }