Problem
When creating localization for mod settings, you can create locale strings for specific string-setting values. Quoting the wiki (https://wiki.factorio.com/Tutorial:Mod_settings#Locale):However, this means that a locale string needs to exist for every single setting, even if every setting shares the same string IDs.[string-mod-setting]
#<setting-name>-<dropdown-item-name>=<translated dropdown item>
my-mod-string-test-setting-item-1=Item 1 localized string
[string-mod-setting-description]
#<setting-name>-<dropdown-item-name>=<tooltip of dropdown item>
my-mod-string-test-setting-item-1=Item 1 localized tooltip
Request
What I want to be able to do is this:Code: Select all
[string-mod-setting-global]
blue=Blue
green=Green
grey=Grey
none=None
...
Code: Select all
[string-mod-setting]
my-mod-available-technology-background-color-grey=Grey
my-mod-available-technology-background-color-blue=Blue
my-mod-available-technology-background-color-green=Green
my-mod-conditionally-available-technology-background-color-grey=Grey
my-mod-conditionally-available-technology-background-color-blue=Blue
my-mod-conditionally-available-technology-background-color-green=Green
my-mod-unavailable-technology-background-color-grey=Grey
my-mod-unavailable-technology-background-color-blue=Blue
my-mod-unavailable-technology-background-color-green=Green
...
Please add a new localization section named "string-mod-setting-global" or similar that the game will check second after "string-mod-setting" that does not require the setting name as part of the locale ID.
Workaround
This is my current workaround, if it helps to understand what I am requesting. Or if anyone else has this problem, here is how I solved it:Create locale files with strings at the root for all of your possible option strings:
Code: Select all
# locale/en/setting-options.cfg
blue=Blue
green=Green
grey=Grey
...
Code: Select all
#!/usr/bin/env lua
data = {}
settings = {}
function data:extend(array)
for _, setting in ipairs(array) do
table.insert(settings, setting)
end
end
require("settings")
for _, lang_file in pairs({...}) do
local file = io.open(lang_file, "r")
local strings = file:read("*all")
file:close()
local locale_strings = {}
for string in strings:gmatch("[^\r\n]+") do
local key, value = string:match("([^=]+)=(.+)")
locale_strings[key] = value
end
file = io.open(lang_file, "w")
file:write("[string-mod-setting]\n")
for _, setting in ipairs(settings) do
if setting.type == "string-setting" and setting.allowed_values then
for _, allowed_value in ipairs(setting.allowed_values) do
local value = locale_strings[allowed_value]
if value then
file:write(setting.name .. "-" .. allowed_value .. "=" .. value .. "\n")
end
end
end
end
file:close()
end
Code: Select all
[string-mod-setting]
my-mod-available-technology-background-color-grey=Grey
my-mod-available-technology-background-color-blue=Blue
my-mod-available-technology-background-color-green=Green
my-mod-conditionally-available-technology-background-color-grey=Grey
my-mod-conditionally-available-technology-background-color-blue=Blue
my-mod-conditionally-available-technology-background-color-green=Green
my-mod-unavailable-technology-background-color-grey=Grey
my-mod-unavailable-technology-background-color-blue=Blue
my-mod-unavailable-technology-background-color-green=Green
...