logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

locale.service.js (1272B)


  1. import languagesObject from '../../i18n/messages'
  2. import ISO6391 from 'iso-639-1'
  3. import _ from 'lodash'
  4. const specialLanguageCodes = {
  5. ja_easy: 'ja',
  6. zh_Hant: 'zh-HANT',
  7. zh: 'zh-Hans'
  8. }
  9. const internalToBrowserLocale = code => specialLanguageCodes[code] || code
  10. const internalToBackendLocale = code => internalToBrowserLocale(code).replace('_', '-')
  11. const internalToBackendLocaleMulti = codes => {
  12. const langs = Array.isArray(codes) ? codes : [codes]
  13. return langs.map(internalToBackendLocale).join(',')
  14. }
  15. const getLanguageName = (code) => {
  16. const specialLanguageNames = {
  17. ja_easy: 'やさしいにほんご',
  18. 'nan-TW': '臺語(閩南語)',
  19. zh: '简体中文',
  20. zh_Hant: '繁體中文'
  21. }
  22. const languageName = specialLanguageNames[code] || ISO6391.getNativeName(code)
  23. const browserLocale = internalToBrowserLocale(code)
  24. return languageName.charAt(0).toLocaleUpperCase(browserLocale) + languageName.slice(1)
  25. }
  26. const languages = _.map(languagesObject.languages, (code) => ({ code, name: getLanguageName(code) })).sort((a, b) => a.name.localeCompare(b.name))
  27. const localeService = {
  28. internalToBrowserLocale,
  29. internalToBackendLocale,
  30. internalToBackendLocaleMulti,
  31. languages,
  32. getLanguageName
  33. }
  34. export default localeService