Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Localization service integration #13

Open
kazupon opened this issue Jul 6, 2018 · 3 comments
Open

Localization service integration #13

kazupon opened this issue Jul 6, 2018 · 3 comments
Labels
Type: Feature Includes new features

Comments

@kazupon
Copy link
Member

kazupon commented Jul 6, 2018

Spec

to support continuous translation in translation service, vue-cli-plugin-i18n provides the following commands:

Commands:

vue-cli-service i18n:set

set the main locale message to localization service

vue-cli-service i18n:update

sync the main locale messages to localization service

vue-cli-service i18n:status

show the status of the localization service.

  • --progress: show the current translation progress at localization service
  • --locales: show the current translation languages

vue-cli-service i18n:pull

pull the locale messages on localization service. default all locales on localization service.

  • --locale: pull the target locale

Configrations

  • VUE_APP_I18N_LOCALIZATION_ID: API user id of localization service
  • VUE_APP_I18N_LOCALIZATION_TOKEN: API token of localization service
@kazupon kazupon added the Type: Feature Includes new features label Jul 6, 2018
@jgribonvald
Copy link

What do you think about adding this function into i18n.js

function checkLang(availableLanguages) {
 // defined from https://gist.github.com/ksol/62b489572944ca70b4ba
  // These window.navigator contain language information
  // 1. languages -> Array of preferred languages (eg ["en-US", "zh-CN", "ja-JP"]) Firefox^32, Chrome^32
  // 2. language  -> Preferred language as String (eg "en-US") Firefox^5, IE^11, Safari,
  //                 Chrome sends Browser UI language
  // 3. browserLanguage -> UI Language of IE
  // 4. userLanguage    -> Language of Windows Regional Options
  // 5. systemLanguage  -> UI Language of Windows
  let browserLanguagePropertyKeys = [
    "languages",
    "language",
    "browserLanguage",
    "userLanguage",
    "systemLanguage"
  ];

  let allLangs = [];
  browserLanguagePropertyKeys.forEach(a => allLangs.push(navigator[a]));
  allLangs = [].concat
    .apply([], allLangs) // merge all values into flattened array
    .filter(v => v) //Remove undefined values
    .map(v => v.substring(0, 2)) //Shorten strings to use two chars (en-US -> en)
    .filter((v, i, a) => a.indexOf(v) === i); // Returns unique values
  let detectedLocale = allLangs.find(x => availableLanguages.includes(x)); //Returns first language matched in available languages

  return detectedLocale || "en"; //If no locale is detected, fallback to 'en'
}

export default new VueI18n({
  locale: checkLang(["fr", "en"]),
  fallbackLocale: 'en',
  messages: loadLocaleMessages()
})

this can be improved, but it permit to auto detect the browser language

@kazupon
Copy link
Member Author

kazupon commented Jul 12, 2018

Thank you for your proposal!

I assume that will plan to integrate with using missing handler and translation service (e.g. locize).

I think that your proposal does not necessarily match the use cases of all applications. 🤔

@jgribonvald
Copy link

yes but providing the function can help for those who wants to use the browser language detection.

@kazupon kazupon pinned this issue May 27, 2019
@kazupon kazupon unpinned this issue Jan 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Feature Includes new features
Projects
None yet
Development

No branches or pull requests

2 participants