Skip to content

Commit

Permalink
RakuAST: move localization reading logic to RakuAST::L10N
Browse files Browse the repository at this point in the history
As one step closer to allow a simple maintenance API of the localization
information
  • Loading branch information
lizmat committed Oct 17, 2023
1 parent 6050735 commit 55952f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 16 additions & 1 deletion lib/RakuAST/L10N.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 1 addition & 8 deletions tools/build/makeL10N.raku
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 55952f6

Please sign in to comment.