-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Messages Internationalization #132
Comments
Can I help? https://github.com/mebjas/html5-qrcode/blob/master/src/strings.ts already separates the UI strings (and considers internationalization a TODO :-), so this looks well prepared for. @mebjas: Have you already thought about how you'd want the internationalization to be triggered/configured? Via an additional config option maybe? It would of course be nice to just automatically match the first language in |
@cheweytoo Thanks for the interest. This has been a key issue in my mind.
I am happy to hear your thoughts on this topic. Different languages baked into the JS code with a config deciding the language is definitely one option. In case of missing language support it could fallback to English. I have not worked on projects where this is purely frontend based. An alternative that comes to mind is generating different JS files for diff languages but that seems like a huge pain for consumers. The design in my mind is:
enum StringMode {
ENGLISH_ONLY, // default
AUTO_DETECT,
EXPLICIT
}
interface StringsConfig {
stringMode: StringMode;
language?: string; // only honoured when stringMode is 'EXPLICIT'.
} And return the impl or default to english if the language is not implemented. Based on contributors we can keep adding more strings. |
Hi all, nice library ! Is there a way to manually set the texts at render or creation time ? I'd like to use Html5QrcodeScanner but I really need it translated. Some workaround comes to your mind? Thanks! |
Hi @mebjas, I'm mostly a backend developer, and I have just general knowledge of JS.
Hi @jpaoletti, I just looked for the phrase I want to translate in the codebase, and just changed it in the code. Of course this solution doesn't work with multilanguage applications. |
@croxarens Yeah I ended up doing that but it is not ideal. I agree with your proposed solution |
If you start the: I'll be glad to help up create Btw thanks for this amazing work @mebjas |
Yes string injection at runtime is the most versatile, no need to hardcode translation then (but it's possible to do both). |
|
Hi all. I am currently working on a React scanning app. Did you find a way to efficacely change language of elements ? |
Will look into this soon. |
we will be very grateful. :) |
One major risk is
We can get the one time effort done for all the current strings.
But thereafter it will add extra task of localisation os every string
before release.
Similarly, with string injection let's say you maintain your own strings -
new changes to api can break your version because of missing string.
Any ideas on how to address these issues?
…On Sat, Nov 19, 2022, 07:26 Juan Cruz Lombardo Bonino < ***@***.***> wrote:
Will look into this soon.
we will be very grateful. :)
—
Reply to this email directly, view it on GitHub
<#132 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAW6HBKAKWCI4XMM7YM4L6TWJAGCBANCNFSM4TEGZICA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
API changes should not break a translated version. At worst, any missing translation should default to English. |
The system should fallback to English if there's anything missing, that way nothing breaks and new releases aren't delayed waiting for the update of every translation. |
let the developer see in the console log the missing string..... |
Got it, it makes sense to me. We would still need a process to keep updating the strings and string changes to as many languages as possible. |
The most important step is to provide a mean for the lib users to inject the translations. Including the translations in the lib itself is a maintenance burden that you may want to avoid. Also, aside of the many languages, some may want to tweak the messages to better suit their use case (more or less verbose for instance). |
On the other hand, developers don't tend to speak all the languages. So an ability to overrule or inject own translations is fine, but having existing translations (maybe in a separate repo) would be extremely helpful. It would also avoid an awful lot of duplicated translation work. |
One way to do that is to use versioning (think versioned API endpoints): Loading an outdated translation set would give a console message. This would make developers aware of the issue, and motivate them to contribute updates. |
Hi @mebjas , Any chance to update https://github.com/scanapp-org/html5-qrcode-react with the language string example I couldn't do this integration on my own, I think it would be more explanatory Thank you |
I translated it for Turkish and this is how I found a solution for now.
|
+1 for this! Would love to to discuss sponsoring the work. |
Sounds good, that'd be helpful - this issue is pretty high up in my radar. I would like to learn more about the use cases - please DM at minhazav@gmail.com Re: sponsorship Checkout https://ko-fi.com/minhazav/tiers - this would definitely help make maintenance more sustainable! |
Based on the workaround of @1sahinomer1 , I developed the following dynamic code that observes the changes that the library does. It is working on Vue, and it should work on vanilla.
|
Hi! I made a PR, can you please check it? |
Bonjour,
et cela permet d'avoir la traduction comme je souhaite au moins ;) |
|
|
I can help with Portuguese if you need |
@croxarens How did you translated in the codebase? Directly inside node_modules? |
Correct! |
But if you update the application with npm install or yarn add, won't it be overwritten again? And I changed inside node_modules but nothing happened :/ |
Sorry, you are right. It was quite a long time ago. I wasn't really into JS so I didn't want to use NPM.
If you do the same inside the node_modules, I guess you'll need to recompile the code and flush the caches (browser included)
Yes, I guess in that case, it would be better to add into the package.json file the version you are currently at, so that npm will not update to the next version, or just clone the project and create a local path I hope this is helpful |
So to confirm, currently we need to modify the source code ourselves if we want to have translated messages at all? Certainly looking at the minified code it's hard to see how we could just configure it with a table of messages in a given language. |
@wizofaus everything is said just above your comment |
Sorry but that comment was about as clear as mud to me. Anyway I worked out my own solution using a MutationObserver. |
So you can share your solution to other at least... |
It's really little different to the one posted above, just a MutationObserver on the element where the QR scanner is initialised, then check all added nodes recursively for text elements. Obviously it relies on deriving translations directly from the existing English text, but that's the system I've been using anyway (and generally works pretty well).
|
Hi there,
is there any way I can translate the messages like "Request Camera Permissions", "Scan an Image File"?
The text was updated successfully, but these errors were encountered: