-
Notifications
You must be signed in to change notification settings - Fork 2
Locale support - base PR #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thomaslaurenson
merged 6 commits into
TheGrayDot:main
from
sjoblomj:locale-support-base
Nov 23, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a7ce924
Allowing users to specify which file properties to list
sjoblomj 4ef8dd8
Fixing test by not displaying platform specific properties and adjust…
sjoblomj 8077cde
Adding scaffolding to support locales
sjoblomj 2a4c1af
Fixing warnings and linting
sjoblomj be76fb9
Correcting conftest setup
sjoblomj 6ccaf50
Adding support for locales when listing
sjoblomj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ add_executable(mpqcli | |
| main.cpp | ||
| mpq.cpp | ||
| helpers.cpp | ||
| locales.cpp | ||
| ) | ||
|
|
||
| # Add dependencies | ||
|
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #include <algorithm> | ||
| #include <fstream> | ||
| #include <vector> | ||
| #include <map> | ||
|
|
||
| #include "locales.h" | ||
|
|
||
| namespace { | ||
| // Files in MPQs have locales with which they are associated. | ||
| // Multiple files can have the same file name if they have different locales. | ||
| // This function maps locales to language names. | ||
| // | ||
| // The mappings are from the Windows Language Code Identifier (LCID). | ||
| // They can be found, for example, here: | ||
| // https://winprotocoldoc.z19.web.core.windows.net/MS-LCID/%5bMS-LCID%5d.pdf | ||
|
|
||
| // Define a bidirectional map for locale-language mappings | ||
| const std::map<uint16_t, std::string> localeToLangMap = { | ||
| {0x000, "enUS"}, // Default - English (US) | ||
| {0x404, "zhTW"}, // Chinese (Taiwan) | ||
| {0x405, "csCZ"}, // Czech | ||
| {0x407, "deDE"}, // German | ||
| {0x409, "enUS"}, // English (US) | ||
| {0x40a, "esES"}, // Spanish (Spain) | ||
| {0x40c, "frFR"}, // French | ||
| {0x410, "itIT"}, // Italian | ||
| {0x411, "jaJP"}, // Japanese | ||
| {0x412, "koKR"}, // Korean | ||
| {0x413, "nlNL"}, // Dutch | ||
| {0x415, "plPL"}, // Polish | ||
| {0x416, "ptPT"}, // Portuguese (Portugal) | ||
| {0x419, "ruRU"}, // Russian | ||
| {0x804, "zhCN"}, // Chinese (Simplified) | ||
| {0x809, "enGB"}, // English (UK) | ||
| {0x80A, "esMX"} // Spanish (Mexico) | ||
| }; | ||
|
|
||
| // Create a reverse map for language to locale lookups | ||
| const std::map<std::string, uint16_t> langToLocaleMap = []() { | ||
| std::map<std::string, uint16_t> reverseMap; | ||
| for (const auto& [locale, lang] : localeToLangMap) { | ||
| if (locale != defaultLocale) { // Skip the default locale to avoid duplication | ||
| reverseMap[lang] = locale; | ||
| } | ||
| } | ||
| return reverseMap; | ||
| }(); | ||
| } | ||
|
|
||
| std::string LocaleToLang(uint16_t locale) { | ||
| auto it = localeToLangMap.find(locale); | ||
| return it != localeToLangMap.end() ? it->second : ""; | ||
| } | ||
|
|
||
| LCID LangToLocale(const std::string& lang) { | ||
| auto it = langToLocaleMap.find(lang); | ||
| return it != langToLocaleMap.end() ? it->second : defaultLocale; | ||
| } | ||
|
|
||
|
|
||
| std::vector<std::string> GetAllLocales() { | ||
| std::vector<std::string> locales; | ||
| for (const auto& [locale, lang] : localeToLangMap) { | ||
| if (locale != defaultLocale) { // Skip the default locale to avoid duplication | ||
| locales.push_back(lang); | ||
| } | ||
| } | ||
| // Sort the locales for consistent output | ||
| std::sort(locales.begin(), locales.end()); | ||
| return locales; | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #ifndef LOCALES_H | ||
| #define LOCALES_H | ||
|
|
||
| #include <string> | ||
| #include <filesystem> | ||
|
|
||
| #include <StormLib.h> | ||
| #include <CLI/CLI.hpp> | ||
|
|
||
| const LCID defaultLocale = 0; | ||
|
|
||
| std::string LocaleToLang(uint16_t locale); | ||
| LCID LangToLocale(const std::string &lang); | ||
| std::vector<std::string> GetAllLocales(); | ||
|
|
||
| // Validator for CLI11 | ||
| const inline auto LocaleValid = CLI::Validator( | ||
| [](const std::string &str) { | ||
| if (str == "default") return std::string(); | ||
|
|
||
| LCID locale = LangToLocale(str); | ||
| if (locale == 0) { | ||
| std::string validLocales = "Locale must be nothing, or one of:"; | ||
| for (const auto& l : GetAllLocales()) { | ||
| validLocales += " " + l; | ||
| } | ||
| return validLocales; | ||
| } | ||
| return std::string(); | ||
| }, | ||
| "Validates locales and outputs valid locales", | ||
| "LocaleValidator" | ||
| ); | ||
|
|
||
| #endif //LOCALES_H |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This list might not be exhaustive. Some locales are mentioned here and here, but both those links appear dated. I don't know if WoW or other games post ~2010 introduced more locales or not. I guess the MPQ format itself allows pretty much any locale value, so the question is which ones have been used by Blizzard. It's trivial to add more later as needed, in any case.