diff --git a/lib/RakuAST/L10N.rakumod b/lib/RakuAST/L10N.rakumod index 6af40178fa1..09cbae52553 100644 --- a/lib/RakuAST/L10N.rakumod +++ b/lib/RakuAST/L10N.rakumod @@ -10,6 +10,19 @@ # Needed for now use experimental :rakuast; +# Produce all words on non-commented lines of given IO as a Slip +sub io2words(IO::Path:D $io) { + $io.lines.map: { .words.Slip unless .starts-with("#") } +} + +# Set up core settings +BEGIN my @core = io2words("tools/templates/L10N/CORE".IO); + +# Read translation hash from given file (as IO object) +sub read-hash(IO::Path:D $io) is export { + %(flat @core, io2words($io)) +} + # Return the AST for translation lookup logic, basically: # # method $name { @@ -297,7 +310,9 @@ my sub deparsify($language, %hash) is export { my $statements := RakuAST::StatementList.new; # Run over the given hash, sorted by key - my @operands = %hash.sort(*.key.fc).map: { + my @operands = %hash.sort(-> $a, $b { + $a.key.fc cmp $b.key.fc || $b.key cmp $a.key + }).map: { (RakuAST::StrLiteral.new(.key), RakuAST::StrLiteral.new(.value)).Slip unless .key.ends-with('-' ~ .value) } diff --git a/tools/build/makeL10N.raku b/tools/build/makeL10N.raku index 473f51570fd..559f0ff9a8a 100755 --- a/tools/build/makeL10N.raku +++ b/tools/build/makeL10N.raku @@ -17,11 +17,6 @@ my $generated := DateTime.now.gist.subst(/\.\d+/,''); my $start := '#- start of generated part of localization'; my $end := '#- end of generated part of localization'; -# all of the words in core (.kv basically) -my @core is List = "tools/templates/L10N/CORE".IO.lines.map: { - .words.Slip unless .starts-with("#") -} - # For all available localizations for dir "tools/templates/L10N".sort(*.basename) -> $io { my str $language = $io.basename; @@ -30,9 +25,7 @@ for dir "tools/templates/L10N".sort(*.basename) -> $io { || $language.starts-with("."); # ignore editor temp files # Create translation hash - my %translation = @core.Slip, $io.lines.map({ - .words.Slip unless .starts-with("#") - }).Slip; + my %translation := read-hash($io); # Create the slang and slangification my $slang := slangify($language, %translation);