logo

pleroma-fe

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

interface_language_switcher.vue (2596B)


  1. <template>
  2. <div class="interface-language-switcher">
  3. <label>
  4. {{ promptText }}
  5. </label>
  6. <ul class="setting-list">
  7. <li
  8. v-for="index of controlledLanguage.keys()"
  9. :key="index"
  10. >
  11. <label>
  12. {{ index === 0 ? $t('settings.primary_language') : $tc('settings.fallback_language', index, { index }) }}
  13. <Select
  14. class="language-select"
  15. :model-value="controlledLanguage[index]"
  16. @update:modelValue="val => setLanguageAt(index, val)"
  17. >
  18. <option
  19. v-for="lang in languages"
  20. :key="lang.code"
  21. :value="lang.code"
  22. >
  23. {{ lang.name }}
  24. </option>
  25. </Select>
  26. </label>
  27. <button
  28. v-if="controlledLanguage.length > 1 && index !== 0"
  29. class="button-default btn"
  30. @click="() => removeLanguageAt(index)"
  31. >
  32. {{ $t('settings.remove_language') }}
  33. </button>
  34. </li>
  35. <li>
  36. <button
  37. class="button-default btn"
  38. @click="addLanguage"
  39. >
  40. {{ $t('settings.add_language') }}
  41. </button>
  42. </li>
  43. </ul>
  44. </div>
  45. </template>
  46. <script>
  47. import localeService from '../../services/locale/locale.service.js'
  48. import Select from '../select/select.vue'
  49. export default {
  50. components: {
  51. // eslint-disable-next-line vue/no-reserved-component-names
  52. Select
  53. },
  54. props: {
  55. promptText: {
  56. type: String,
  57. required: true
  58. },
  59. language: {
  60. type: [Array, String],
  61. required: true
  62. },
  63. setLanguage: {
  64. type: Function,
  65. required: true
  66. }
  67. },
  68. computed: {
  69. languages () {
  70. return localeService.languages
  71. },
  72. controlledLanguage: {
  73. get: function () {
  74. return Array.isArray(this.language) ? this.language : [this.language]
  75. },
  76. set: function (val) {
  77. this.setLanguage(val)
  78. }
  79. }
  80. },
  81. methods: {
  82. getLanguageName (code) {
  83. return localeService.getLanguageName(code)
  84. },
  85. addLanguage () {
  86. this.controlledLanguage = [...this.controlledLanguage, '']
  87. },
  88. setLanguageAt (index, val) {
  89. const lang = [...this.controlledLanguage]
  90. lang[index] = val
  91. this.controlledLanguage = lang
  92. },
  93. removeLanguageAt (index) {
  94. const lang = [...this.controlledLanguage]
  95. lang.splice(index, 1)
  96. this.controlledLanguage = lang
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="scss">
  102. .interface-language-switcher {
  103. .language-select {
  104. margin-right: 1em;
  105. }
  106. }
  107. </style>