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

feat: 新增多语言基础配置 #35

Merged
merged 1 commit into from
May 14, 2024
Merged

feat: 新增多语言基础配置 #35

merged 1 commit into from
May 14, 2024

Conversation

hgraceb
Copy link
Contributor

@hgraceb hgraceb commented May 14, 2024

  1. 示例代码
<template>
  <el-button :title="$t('example.placeholder', ['title'])" @click="toggleLanguage">
    {{ $t('example.placeholder', ['template']) }}
  </el-button>
</template>

<script setup lang='ts'>
import i18n from '@/i18n'
import { useI18n } from 'vue-i18n'
import { ElMessage } from 'element-plus'
import { en } from '@/i18n/locales/en'
import { zhCn } from '@/i18n/locales/zh-cn'
import { zhTw } from '@/i18n/locales/zh-tw'

const { t } = useI18n()

const toggleLanguage = () => {
  switch (i18n.global.locale.value) {
    case zhCn.local:
      i18n.global.locale.value = zhTw.local
      break
    case zhTw.local:
      i18n.global.locale.value = en.local
      break
    default:
      i18n.global.locale.value = zhCn.local
      break
  }
  ElMessage.info(`${t('example.placeholder', [i18n.global.locale.value])}`)
}
</script>
  1. 编写时可以根据需求决定是否安装额外的插件 https://vue-i18n.intlify.dev/ecosystem/tools.html 进行多语言代码索引提示,不过好像都不是很好用的样子

@eee555 eee555 merged commit c5a6799 into eee555:main May 14, 2024
2 checks passed
@putianyi889 putianyi889 mentioned this pull request May 22, 2024
14 tasks
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