Skip to content
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

Qt: Localization support #9009

Merged
merged 7 commits into from
Jun 20, 2023
Merged

Qt: Localization support #9009

merged 7 commits into from
Jun 20, 2023

Conversation

stenzek
Copy link
Member

@stenzek stenzek commented Jun 19, 2023

Description of Changes

Adds support for marking core strings for translation, and sets Qt up to parse them (e.g. OSD messages).

Adds language selection to Qt.

As an aside, I'm a bit sad that lupdate seems to ignore aliased functions with incorrect numbers of parameters. I originally had a TRANSLATE_FMT helper which forwarded the result to translate/fmt automatically.. instead we have to make do with fmt::format(TRANSLATE_SV(....

Documentation:

To mark a string for translation:

  • Use TRANSLATE(context, message) for a C string.
  • Use TRANSLATE_SV(context, message) to get a std::string_view back.
  • Use TRANSLATE_FMT(context, message) to get a std::string back.
  • If you don't need the string evaluated, and just want to expose it for use elsewhere (e.g. pad types/bindings), then use TRANSLATE_NOOP(context, message).
  • When providing format strings for translation, if there's more than one field, then use numbered references. i.e. don't write fmt::format(TRANSLATE_SV("USB", "{} set to {}.", x, y)), write fmt::format(TRANSLATE_SV("USB", "{0} set to {1}.", x, y)). Not all languages follow the same word ordering.
  • When inside pcsx2-qt, use the Qt routines instead. i.e. tr() and qApp->translate().

I've wrote a simple-ish caching system for message to avoid runtime string allocation, mainly for when I mark the big picture UI as translatable later. I'll probably do a compile-time string hashing system on top of that, to make lookups faster, but for now this'll do.

For ImGui, the glyph ranges used by your language need to be extracted. There's a Python script under translations which should be run after pulling in .ts file updates.

To add a new language:

  1. Pull the .ts file from crowdin (we'd probably want to automate this..).
  2. Add the language to QtHost::GetAvailableLanguageList(). Preferably using the native title for the language. The second part of the pair should match the two-letter country code, or with the region hyphenated.
  3. (optional) Add the .ts file to the Visual Studio project. You don't need to, msbuild globs it.
  4. Add the .ts file to pcsx2-qt's CMakeLists.txt under TS_FILES. You must add it.
  5. If your language uses non-latin character glyphs, you may need to use a different font and glyph range for ImGui. Follow the Japanese/Chinese examples in Translations.cpp.

Rationale behind Changes

One step closer to 2.0 release.

Suggested Testing Steps

Make sure pad and USB configuration still works.
Make sure OSD messages aren't broken.

@stenzek stenzek merged commit 703c02c into PCSX2:master Jun 20, 2023
12 checks passed
@stenzek stenzek deleted the i18n branch June 20, 2023 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants