- Lua 70.6%
- Python 29.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .forgejo/workflows | ||
| scripts | ||
| src | ||
| .editorconfig | ||
| .gitattributes | ||
| .gitignore | ||
| .luarc.json | ||
| icon.png | ||
| mod.json | ||
| README.md | ||
Better French Translate
A Lua mod script for dumping and applying game localization data as one JSON file per language.
What this mod does
This script has two jobs:
- Dump localization data from the game into JSON files.
- Load the French JSON and patch the game text at runtime.
The format is designed so that each language stays separate:
localization/En_Us.jsonlocalization/Fr_Fr.json- and so on for every language the game exposes
Each JSON file contains:
- the game version metadata
- the language code
- a map of
id -> text
Example structure:
{
"version": {
"build": 1004637,
"branch": "ea_update_08",
"date": "2026-04-23",
},
"language": "Fr_Fr",
"entries": {
"122361": "...",
"945922580": "..."
}
}
Features
- One file per language
- Stable ordering of IDs in exported JSON
- Safe JSON escaping for:
- quotes
- backslashes
- tabs
- newlines
- other control characters
- Version parsing for compatibility checks
- Built-in JSON loader for the translation file
- Runtime patching of the French localization
File layout
The script exports files into a localization/ folder relative to the mod export directory.
Expected export examples:
localization/Fr_Fr.jsonlocalization/En_Us.json
How it works
1. Version parsing
The script reads game.version and extracts:
build: numeric build number used for comparisonbranch: branch namedate: build date
This is used to compare the translation file against the current game build.
2. Dumping localization
The dump function:
- gets all
keen::LocaTagCollectionResourceresources - iterates over every language exposed by the game
- reads each language’s tags
- exports one JSON file per language
Only unique IDs are written.
3. Loading and applying French text
At runtime, the script:
- loads
localization/Fr_Fr.json - checks the version metadata
- warns if the saved build differs from the current game build
- replaces matching French localization entries by ID
How to use
Step 1: Install the script
Put the Lua file in your mod loader setup and enable it.
Step 2: Dump the localization files
Temporarily enable the dump function by uncommenting:
-- dump_localization()
and commenting out:
apply_translation()
Then run the game once to generate the JSON files.
Step 3: Translate the French file
Open localization/Fr_Fr.json and translate the values inside entries.
Keep the IDs unchanged.
Example:
"122361": "Notre nouvel allié forgera peut-être votre épée..."
Step 4: Re-enable translation
Once the French file is ready:
- comment out
dump_localization() - keep
apply_translation()enabled
The mod will then load the French JSON and patch the game text.
Important rules when translating
Do not remove or break formatting placeholders, such as:
%s%d<b>...</b><i>...</i>- line breaks represented by
\n
These are often required by the game UI.
Compatibility behavior
The JSON file stores the build number from game.version.
When the mod loads a translation file, it compares:
- saved build number
- current game build number
If the build differs, the script prints a warning.
This helps detect when a game update may have changed localization IDs.
Notes
- The script currently applies the French translation from
Fr_Fr.json. - The export still supports every language the game exposes.
- The translation files stay separate by language on purpose.
io.export()is used instead ofio.open()because the mod environment blocks direct file writing.
Troubleshooting
No file is exported
Make sure export capability is enabled in the mod environment.
French text does not appear in game
Check that:
localization/Fr_Fr.jsonexists- the JSON is valid
- IDs in the JSON match the game IDs
apply_translation()is enabled
JSON parse errors
This usually means one of the translation strings contains invalid JSON characters or the file was edited in a way that broke quoting.
Branches
| Branch | Content |
|---|---|
main |
The localization the mod uses. It is the authority for the French text. Weblate translates it. |
localization |
Weblate pushes its translations here, then they are merged into main. |
raw |
Only pure game dumps, one commit per game build. Never edit it by hand. |
Updating for a new game build
1. Dump the new build
In src/mod.lua, uncomment dump_localization() and run the game once. The dump is written to
<Enshrouded>/export/localization/. Comment the line again afterwards.
2. Commit the dump on raw
git switch raw
cp "<Enshrouded>/export/localization/En_Us.json" "<Enshrouded>/export/localization/Fr_Fr.json" src/
git commit -am "Game build <build>"
git push origin raw
git switch main
Commit the files exactly as the dump wrote them: no edits, no reformatting.
3. Review the pull request
Pushing raw starts the Merge game update workflow (.forgejo/workflows/raw-merge.yml). It merges raw
into a new update/raw-<build> branch and opens a pull request to main. The pull request description lists:
- new entries from the game
- game updates applied to entries
mainnever translated - entries removed by the game
- conflicts: entries both sides changed.
mainis kept, check the game's new text - entries whose English changed while
main's translation was kept
Fix what needs fixing on the update/raw-<build> branch or later in Weblate, then merge the pull request.
Weblate marks a translation as needs editing when its English source changed.
How the merge works
Git compares both sides to the last raw build already merged into main, not main to raw. So an entry
is only taken from the game if main never changed it since that build. Your translations stay.
scripts/merge_loc.py does this entry by entry, as the lockeys merge driver declared in .gitattributes.
Git's own line merge would stop on neighbouring lines. To use the driver for a local merge, configure it once:
git config merge.lockeys.driver "python scripts/merge_loc.py driver %O %A %B"
Without this setting, git silently falls back to its line merge. To merge by hand without the script, run
git config merge.conflictStyle diff3 before git merge raw. In each conflict, take raw's line when
main's line is identical to the base, otherwise keep main's line.
Before a merge, the same script prints the pull request report:
python scripts/merge_loc.py report $(git merge-base main raw) main raw
Future improvements
Possible upgrades for later:
- validation for placeholders like
%s - optional export of only visible UI strings
- translation QA checks