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

Messages Internationalization (#132) #755

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

alvedder
Copy link

Hi colleagues!

I suggest the following solution:

  • Internally translations are redone using a translation object where the values are accessible via keys like "scanner.scanningStatus" resembling i18next library.
  • Added ability for user to set global translations via setTranslations function exported from the package.
  • User may pass a partial translation object, then missing values are taken from the default translation object.

I guess the main pros of this approach is that it's not needed to make translations to many languages and then support them all. Those who really need it may set their own translations as they like.

If the solution is fine, I'll write unit tests and other stuff I might've missed.

@patocardo
Copy link

I see how you abstracted the strings, but I don't see how translated text are provided. If you create tests, please add that part too

@alvedder
Copy link
Author

Here is the part that lets you provide translations, it's exported from the package

https://github.com/mebjas/html5-qrcode/pull/755/files#diff-02160ba07eff05a69221c9bc72112051809b5844bd9edb325984d97ece98d645R82-R84

The usage is pretty simple:

import { setTranslations } from 'html5-qrcode';

const myOwnTranslationObject = {
    "common": {
      "cameraStreamingNotSupported": "Потоковое воспроизведение камеры не поддерживается браузером.",
      "unableToQuerySupportedDevices": "Невозможно запросить поддерживаемые устройства, неизвестная ошибка."
    },
    ...
 }
 
setTranslations(myOwnTranslationObject);

Also it's easy to use with translation libraries, for i18next it would be so:

import { t } from 'i18next';
import { setTranslations } from 'html5-qrcode';

setTranslations(t('html5QrCode', { returnObjects: true }));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants