Request: Make check_prototype_translations() more useful

Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Request: Make check_prototype_translations() more useful

Post by Pi-C »

I'd like to have an extended version of game.check_prototype_translations(). According to my observations, the function will currently only report prototype names that have not been localized for any language. In other words: If a name has been localized for language A, but not for language B, it won't be reported even if B is the currently active language of Factorio. I believe it would be useful if we could pass a list of languages that should be checked to this function, e.g.:

Code: Select all

game.check_prototype_translations({"en", "ru", "de", "it"})
I don't intend this to be used in real games -- but it would be immensely helpful if modders could use this during development to check if their localization for a given language is complete. My use case is that I'm collaborating on mods that define a lot of new prototypes -- most in the obvious places, some hidden in update functions to sustain compatibility with other mods. As an outsider working on such mods that define so much in so many files (distributed over several directories), I find it hard to keep track of all names. Being able to call this function during testing would help me to make sure that all localizations are complete. It would be really nice if you could implement this feature! :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Request: Make check_prototype_translations() more useful

Post by Pi-C »

Code: Select all

game.check_prototype_translations({"en", "ru", "de", "it"})
One more idea: As game.check_prototype_translations() checks all active mods for missing localizations, the report can be quite long and difficult to parse. So, an optional argument with the names of the mods to check would make the function complete faster and limit the report to actually relevant (because requested) output. Something like this:

Code: Select all

game.check_prototype_translations({"en", "ru", "de", "it"}, {"my_mod_1", "my_mod_2", "my_mod_3"})
That would only look in my_mod_1-3 for keys that have not been localized for English, Russian, German, and Italian.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Request: Make check_prototype_translations() more useful

Post by Rseding91 »

The way locale works the function can only ever check the active language. Which is exactly what it does and it checks all values the game expects to have translations for; mods included.

If you want to check other languages, switch to that language and run it again.
If you want to get ahold of me I'm almost always on Discord.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Request: Make check_prototype_translations() more useful

Post by Pi-C »

Rseding91 wrote:
Thu Feb 13, 2020 2:44 pm
If you want to check other languages, switch to that language and run it again.
I actually played around with this yesterday. First, I was running with the default language, and got 41 strings reported (remnants, corpses, trees etc. that don't need a translation). I then commented out some strings in the Russian localization and tested again (with English). The deactivated strings were not reported, as expected, because this was not the active language. Then I switched the game to use Russian. Again, I got just a report for the 41 completely unlocalized strings, but not for the strings I'd deactivated in locale/ru/ru.cfg. Either I made a mistake and removed unused strings (I'll have to check again to be sure -- it was quite late last night), or it really doesn't work as expected yet. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Request: Make check_prototype_translations() more useful

Post by Rseding91 »

Pi-C wrote:
Thu Feb 13, 2020 3:07 pm
Rseding91 wrote:
Thu Feb 13, 2020 2:44 pm
If you want to check other languages, switch to that language and run it again.
I actually played around with this yesterday. First, I was running with the default language, and got 41 strings reported (remnants, corpses, trees etc. that don't need a translation). I then commented out some strings in the Russian localization and tested again (with English). The deactivated strings were not reported, as expected, because this was not the active language. Then I switched the game to use Russian. Again, I got just a report for the 41 completely unlocalized strings, but not for the strings I'd deactivated in locale/ru/ru.cfg. Either I made a mistake and removed unused strings (I'll have to check again to be sure -- it was quite late last night), or it really doesn't work as expected yet. :-)
It's possible that it's broken some how, but it's also what we've been using for several years now. So, just let me know if you think you find something.

Not every string is required by the game; descriptions are optional so if you "don't have" those it's not an error. Same for some other things.
If you want to get ahold of me I'm almost always on Discord.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Request: Make check_prototype_translations() more useful

Post by Pi-C »

Rseding91 wrote:
Thu Feb 13, 2020 3:36 pm
It's possible that it's broken some how, but it's also what we've been using for several years now. So, just let me know if you think you find something.

Not every string is required by the game; descriptions are optional so if you "don't have" those it's not an error. Same for some other things.
This is from the English locale file:

Code: Select all

[recipe-name]
bi-dart-turret=Dart turret
bi-dart-magazine-basic=Basic dart ammo
bi-dart-magazine-standard=Standard dart ammo
bi-dart-magazine-enhanced=Enhanced dart ammo
bi-dart-magazine-poison=Poison dart ammo
bi-dart-magazine-basic-c=Conversion basic dart ammo
bi-dart-magazine-standard-c=Conversion standard dart ammo
bi-dart-magazine-enhanced-c=Conversion enhanced dart ammo
bi-dart-magazine-poison-c=Conversion poison dart ammo
bi-dart-rifle=Dart Rifle
This is from the Russian locale file:

Code: Select all

[recipe-name]
bi_recipe_dart_turret=Дротиковая турель
bi_recipe_basic_dart_magazine=Базовый дротиковый снаряд
bi_recipe_standard_dart_magazine=Standard Dart Ammo
bi_recipe_enhanced_dart_magazine=Продвинутый дротиковый снаряд
bi_recipe_poison_dart_magazine=Poison Dart Ammo
bi_recipe_basic_dart_magazine_c=Conversion Basic Dart Ammo
bi_recipe_standard_dart_magazine_c=Conversion Standard Dart Ammo
bi_recipe_enhanced_dart_magazine_c=Conversion Enhanced Dart Ammo
bi_recipe_poison_dart_magazine_c=Conversion Poison Dart Ammo
bi_recipe_bi_dart_rifle=Dart Rifle
Recipes have been renamed in the mod, the English translation has already been updated, the Russian translation still has the old names. Thus, if Factorio is running with Russian locale, it should report missing recipe keys. I call game.check_prototype_translations() in on_init().

Starting a new game with the English locale:

Code: Select all

 202.285 Checksum for script __Natural_Evolution_Buildings__/control.lua: 2625040933
 202.285 Info LuaGameScript.cpp:2298: ammo-category "Bio_Cannon_Ammo" (Natural_Evolution_Buildings) has no translation.
 202.285 Info LuaGameScript.cpp:2298: ammo-category "Bio_Turret_Ammo" (Natural_Evolution_Buildings) has no translation.
 202.285 Info LuaGameScript.cpp:2298: ammo-category "NE_Conversion_Ammo" (Natural_Evolution_Buildings) has no translation.
 202.285 Info LuaGameScript.cpp:2298: ammo-category "Terraforming_Station" (Natural_Evolution_Buildings) has no translation.
 202.285 Info LuaGameScript.cpp:2298: entity "Natural-Evolution-Spitter-Spawner-corpse" (Natural_Evolution_Buildings) has no translation.
 202.285 Info LuaGameScript.cpp:2298: entity "Natural-Evolution-Biter-Spawner-corpse" (Natural_Evolution_Buildings) has no translation.
 202.285 Info LuaGameScript.cpp:2298: entity "Bio-Cannon-r" (Natural_Evolution_Buildings) has no translation.
 202.287 Verbose Scenario.cpp:351: Map setup finished: 0.050404 seconds.
Everything is as expected: The recipes have been translated to English, so there's no need to output a warning. (There are unrecognized names, but they really don't need to be translated.)

Now, I've switched the language to Russian, restarted Factorio, and started a new game again:

Code: Select all

  69.580 Checksum for script __Natural_Evolution_Buildings__/control.lua: 2625040933
  69.581 Info LuaGameScript.cpp:2298: ammo-category "Bio_Cannon_Ammo" (Natural_Evolution_Buildings) has no translation.
  69.581 Info LuaGameScript.cpp:2298: ammo-category "Bio_Turret_Ammo" (Natural_Evolution_Buildings) has no translation.
  69.581 Info LuaGameScript.cpp:2298: ammo-category "NE_Conversion_Ammo" (Natural_Evolution_Buildings) has no translation.
  69.581 Info LuaGameScript.cpp:2298: ammo-category "Terraforming_Station" (Natural_Evolution_Buildings) has no translation.
  69.581 Info LuaGameScript.cpp:2298: entity "Natural-Evolution-Spitter-Spawner-corpse" (Natural_Evolution_Buildings) has no translation.
  69.581 Info LuaGameScript.cpp:2298: entity "Natural-Evolution-Biter-Spawner-corpse" (Natural_Evolution_Buildings) has no translation.
  69.581 Info LuaGameScript.cpp:2298: entity "Bio-Cannon-r" (Natural_Evolution_Buildings) has no translation.
  69.583 Verbose Scenario.cpp:351: Map setup finished: 0.044683 seconds.
The same strings that get reported as before -- but it should be more because there are no matching keys for the renamed prototypes in the old Russian locale. Actually, it should look like this:

Code: Select all

  21.556 Checksum for script __Natural_Evolution_Buildings__/control.lua: 2625040933
  21.556 Info LuaGameScript.cpp:2298: ammo-category "Bio_Cannon_Ammo" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: ammo-category "Bio_Turret_Ammo" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: ammo-category "NE_Conversion_Ammo" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: ammo-category "Terraforming_Station" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: entity "bio-land-mine" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: entity "battle-marker" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: entity "Natural-Evolution-Biter-Spawner" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: entity "Natural-Evolution-Spitter-Spawner" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: entity "AlienControlStation-Area" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: entity "TerraformingStation-New" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: entity "Alien-Hatchery" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: entity "Natural-Evolution-Spitter-Spawner-corpse" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: entity "Natural-Evolution-Biter-Spawner-corpse" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: entity "Artifact-collector-r" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: entity "TerraformingStation-c" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: entity "Bio-Cannon-r" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: fluid "NE-alien-toxin" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: fluid "NE-enhanced-nutrient-solution" (Natural_Evolution_Buildings) has no translation.
  21.556 Info LuaGameScript.cpp:2298: fluid "NE-nutrient-solution" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: fluid "NE-revitalization-solution" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "NE-alien-revitalization" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "NE-basic-alien-nutrientant" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "NE-enhanced-alien-nutrientant" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "bi-dart-magazine-basic" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "bi-dart-magazine-basic-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "bi-dart-magazine-standard" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "bi-dart-magazine-standard-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "bi-dart-magazine-enhanced" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "bi-dart-magazine-enhanced-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "bi-dart-magazine-poison" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "bi-dart-magazine-poison-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "Alien-Hatchery" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "Natural-Evolution-Biter-Spawner" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "Natural-Evolution-Biter-Spawner-refresh" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "firearm-magazine-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "copper-bullets-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "piercing-rounds-magazine-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "Biological-bullet-magazine-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "uranium-rounds-magazine-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "Building-Materials" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "AlienControlStation" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "Natural-Evolution-Spitter-Spawner" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "Natural-Evolution-Spitter-Spawner-refresh" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "TerraformingStation" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "pheromone-concrete" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "rejuvenate-pheromone-concrete" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: recipe "bio-land-mine" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: tile "exhausted-pheromone-concrete" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: tile "pheromone-concrete" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "pheromone-concrete" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "exhausted-pheromone-concrete" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "Building-Materials" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "bio-land-mine" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "bi-dart-magazine-basic" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "bi-dart-magazine-basic-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "bi-dart-magazine-standard" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "bi-dart-magazine-standard-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "bi-dart-magazine-enhanced" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "bi-dart-magazine-enhanced-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "bi-dart-magazine-poison" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "bi-dart-magazine-poison-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "firearm-magazine-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "copper-bullet-magazine-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "piercing-rounds-magazine-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "Biological-bullet-magazine-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "uranium-rounds-magazine-c" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "battle-marker" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "Natural-Evolution-Biter-Spawner" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "Natural-Evolution-Biter-Spawner-exhausted" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "Natural-Evolution-Spitter-Spawner" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "Natural-Evolution-Spitter-Spawner-exhausted" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "Alien-Hatchery" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "AlienControlStation-Area" (Natural_Evolution_Buildings) has no translation.
  21.557 Info LuaGameScript.cpp:2298: item "TerraformingStation-New" (Natural_Evolution_Buildings) has no translation.
  21.559 Verbose Scenario.cpp:351: Map setup finished: 0.044492 seconds.
This is what I've got after moving the English locale file out of the way and starting the game with the Russian locale again. It demonstrates that check_protoype_translations() doesn't really look at only the active locale. Keys that have been translated to any language -- whether it is the active language or not -- will not be reported as missing.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Request: Make check_prototype_translations() more useful

Post by Rseding91 »

Ah yes, there's the fallback system. Locale falls back to English if the active language doesn't have a key so it doesn't show missing locale entries as other languages update. I can change the check logic so it doesn't use the fallback system because.... well that's kind of the point of the check function :P

Or, at least have it report as a warning and not an error?
If you want to get ahold of me I'm almost always on Discord.

User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2528
Joined: Fri Nov 06, 2015 7:41 pm

Re: Request: Make check_prototype_translations() more useful

Post by Deadlock989 »

[removed - wrong thread]
Last edited by Deadlock989 on Tue Feb 18, 2020 11:21 am, edited 1 time in total.
Image

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Request: Make check_prototype_translations() more useful

Post by Pi-C »

Rseding91 wrote:
Tue Feb 18, 2020 11:03 am
Ah yes, there's the fallback system. Locale falls back to English if the active language doesn't have a key so it doesn't show missing locale entries as other languages update. I can change the check logic so it doesn't use the fallback system because.... well that's kind of the point of the check function :P

Or, at least have it report as a warning and not an error?
Oh, fallback -- so it's not "any language" but English that needs to have a locale. Good to know. :-)

It would be really nice if you could change the check. In my opinion it doesn't really matter whether you output warnings or errors. check_prototype_translations() shouldn't be used by mods (only during development), and if I'm testing the localizations, I need the list of missing keys, but I don't want the game to start (because I'll have to restart shortly after with changed locale files anyway).
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Implemented mod requests”