i18n, a way to pass values and call functions through tm.

When we use i18n, sometimes we need to call a function and then return the corresponding value for display. At this time, it cannot be used and must be $tused $tm. The specific value transfer method and the method for the function in the i18n file to get the value are as follows:

//需要在main中把i18n给export出来
import i18n from "@/temp/test/main";
const {
    
    tm}=i18n.global
 f.msg = tm(pre.value + "check")(
              i + 1,temp
 );

The main file is written as follows:

const i18n = createI18n({
    
    
  // 默认语言
  locale: 'zh',
 globalInjection: true,
  messages: {
    
    
    zh: Chinese,
    en: English,
  },
})
//暴露出来
export default i18n
app.use(i18n)

The i18n file is written as follows:

  check(first, index) {
    
    
   let str = first  + '第' + index + '项内容不能为空'
   //需要return返回展示的值
   return str
  },

Guess you like

Origin blog.csdn.net/weixin_45807026/article/details/126807137