logo

pleroma-fe

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

locale.service.js (1321B)


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