Ali*_*bah 6 javascript internationalization head right-to-left nuxt.js
我想添加一个条件如下
if(app.i18n.locale == 'ar')
Run Code Online (Sandbox Code Playgroud)
我在这个项目中使用阿拉伯语和英语。如果当前语言是阿拉伯语,则在头部添加bootstrap-rtl.css,如果当前语言en名为bootstrap.css,我尝试了不止一种方法,都没有成功。
例如在插件文件夹中添加一个文件direction-control.js
export default ({ app }, inject) => {\n const dir = () =>\n app.i18n.locales.find((x) => x.code === app.i18n.locale)?.dir;\n inject('dir', dir);\n };\nRun Code Online (Sandbox Code Playgroud)\n当你的nuxt.config.js需要与此类似的代码
plugins: [\n '~/plugins/direction-control', // your plugins file name\n // other plugins\n ],\n modules: [\n [\n 'nuxt-i18n',\n {\n locales: [\n {\n code: 'en',\n file: 'en.json',\n dir: 'ltr',\n name: 'English',\n },\n {\n code: 'ar',\n file: 'ar.json',\n dir: 'rtl', // that will be passed to your app\n name: '\xd8\xb9\xd8\xb1\xd8\xa8\xd9\x8a',\n },\n ],\n langDir: 'translations/',\n defaultLocale: 'ar',\n },\n ],\n ],\nRun Code Online (Sandbox Code Playgroud)\n现在是时候获取目录了
\nexport default {\n mounted() {\n console.log(this.$dir()); // logs your direction 'ltr' or 'rtl'\n console.log(this.$i18n.locale);\n if (this.$i18n.locale == "ar") {\n // make some action\n }\n },\n}\nRun Code Online (Sandbox Code Playgroud)\n或像这样的内部模板
\n<template>\n <div :dir="$dir()">\n <Nuxt />\n </div>\n</template>\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
2651 次 |
| 最近记录: |