Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the language module to support adding/merging localization “packs” at runtime, introduces a central registry for language sources and the current translation dictionary, and updates docs/tests to cover the new behavior.
Changes:
- Add
lang.load_langs(pack_id, langs, [on_lang_changed])and alang_registrythat merges base + pack translations when switching/refreshing a language. - Add support for custom loader functions (intended for async/bundle/HTTP loading) and move logger functionality into
lang/internal/lang_logger.lua. - Expand test coverage for pack loading/merging and add a sample pack JSON file; update README API docs accordingly.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
test/test_lang.lua |
Adds tests covering runtime pack loading (merge into current lang, add new lang, CSV pack). |
resources/lang/en_pack.json |
Adds a small English “pack” translation file used by tests. |
README.md |
Updates initialization/docs and adjusts set_lang signature; should also surface load_langs in the quick API list. |
lang/lang.lua |
Introduces load_langs, routes language operations through lang_registry, and makes set_lang callback-based. |
lang/lang_registry.lua |
New registry handling available languages, packs, merging, and optional async loaders. |
lang/lang_internal.lua |
Refactors CSV parsing and adds helper utilities for format detection/merging/loading. |
lang/internal/lang_logger.lua |
New logger module; needs a small safety fix for non-string keys in logged tables. |
game.project |
Adds an HTML5 splash image configuration entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+54
to
+59
| function M.setup_langs(available_langs) | ||
| LANGS_ORDER = {} | ||
| AVAILABLE_LANGS_MAP = {} | ||
| LANG_DICT = {} | ||
|
|
||
| for _, lang_data in ipairs(available_langs) do |
Comment on lines
+90
to
+94
| for _, pack_langs in pairs(LANG_PACKS) do | ||
| for _, lang_data in ipairs(pack_langs) do | ||
| if lang_data.id == lang_id then | ||
| table.insert(sources, lang_data) | ||
| end |
Comment on lines
+146
to
+150
| for _, source in ipairs(async_sources) do | ||
| local path_str = source.path --[[@as string]] | ||
| source.loader(path_str, function(content) | ||
| local lang_table = lang_internal.parse_lang_content(content, lang_id, path_str) | ||
| if lang_table then |
Comment on lines
+54
to
+60
| if type(value) == "table" then | ||
| if depth == 0 then | ||
| local table_len = 0 | ||
| for _ in pairs(value) do | ||
| table_len = table_len + 1 | ||
| end | ||
| result = result .. key .. ": {... #" .. table_len .. "}" |
Comment on lines
181
to
183
| lang.init(available_langs, [lang_on_start]) | ||
| lang.set_lang(lang_id) | ||
| lang.set_lang(lang_id, [on_lang_changed]) | ||
| lang.get_lang() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.