-
-
Notifications
You must be signed in to change notification settings - Fork 491
Localization Support #4386
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
base: master
Are you sure you want to change the base?
Localization Support #4386
Conversation
Great job! This solution should be more efficient than Lua based options. I'm wondering if it's feasible to add this functionality on client level (so translations could be shared across all resources). This way complex projects can use a single resource to load translation files and avoid using exports / call. |
085ebe1
to
317c63c
Compare
Personally, I'd rather implement this in Lua instead of directly in the project. It's easy to do there, and not every server actually needs it. Even if some do, the PO file based setup feels outdated now and probably wouldn't match what a lot of folks prefer. |
The overhead of doing this in Lua is actually pretty minimal, especially for most use cases. You can load translations once in a resource and share them with others using call or even loadstring if needed. |
What about exploring another solution instead of using Lua? I still believe there might be an option that satisfies both. |
Personally, I think this is a very good idea. It’s true that this can be achieved using regular Lua tables, but using .po files seems like a better, more appropriate, and professional solution, as it allows integration with automated platforms like Crowdin. Additionally, it’s much simpler and easier than building an entire translation system from scratch. If someone prefers their own Lua-based solution, they can still stick with it—nobody is forced to use .po files. Using .po files is by no means outdated; the format is still widely used in the translation industry, and I see no reason why it couldn’t be used for translations on your server. It’s fully sufficient and straightforward. As we can see from the reactions, this PR has been received positively. The only thing I personally miss is some kind of automatic scaling option. Unfortunately, even MTA doesn’t currently have this feature. Specifically, I mean something like what’s used in GTA code—different languages have different characters; a short word in one language might be long in another, not to mention entire sentences. As a result, content in different languages is often cut off or not fully visible. For example, buttons may be too narrow to fit the same text in various languages (like in the admin panel). I’m not sure if this should be a separate PR or part of this one, or maybe it’s something that should be handled independently in Lua. |
- Resolved include conflict in CLuaManager.cpp by adding both CLuaTranslationDefs.h and CIdArray.h - Resolved CResourceStartPacket.cpp conflict by preserving translation support from feat/localization branch - Added translation file type handling and global translation provider flag support
✅ tasks
This PR adds localization support for MTA resources using
.po
files. Resources can include translation files directly in theirmeta.xml
and use functions to get translated text.Addresses Issue
Resolves the localization framework request in [mtasa-resources#361] (Thanks to jlillis for the suggestion), enabling multi-language support instead of a single language.
Features
<translation src="locales/en.po" primary="true" />
tags inmeta.xml
New Functions
Server-Side:
getTranslation(msgid [, lang])
→ stringgetAvailableTranslations()
→ tableClient-Side:
getTranslation(msgid [, lang])
→ stringgetCurrentTranslationLanguage()
→ stringsetCurrentTranslationLanguage(lang)
→ booleangetAvailableTranslations()
→ tableHow it works
Resources place
.po
files in alocales/
folder (or any folder inside the resource) and declare them inmeta.xml
. The system loads translations on resource start. Missing translations fallback to the primary language, then to the first imported language, or finally the original message ID. The primary language is set withprimary="true"
; otherwise, the first translation file becomes the primary.Details
tinygettext
libraryTesting
test_localization.zip
Additional translation functions will be added in future updates to expand functionality.