我正在翻译使用Blade模板的Laravel网站,并想知道是否有更好的方法来翻译链接,如下所示:
应用程序/郎/ EN/contact.php:
return [
'1' => 'text before link',
'2' => 'link text',
'3' => 'text after link'
];
Run Code Online (Sandbox Code Playgroud)
应用程序/视图/ contact.blade.php:
<p>{{ Lang::get('contact.1') }}
<a herf="{{URL::route('home')}}">{{ Lang::get('contact.2') }}</a>
{{ Lang::get('contact.3') }}}</p>
Run Code Online (Sandbox Code Playgroud) 在我的 Vue 3 应用程序中,用户可以为自己制作多语言页面。他们可以决定其页面上可用的语言。可用的语言是从 API 加载的。
语言加载到 Pinia 存储中,LanguageSwitcher.vue 组件根据浏览器设置、URL 中的语言变量、默认区域设置和可用语言加载默认语言。所有这些都需要严格的赛普拉斯测试,其中之一是确保页面上显示的所选语言实际上是所选的语言。但是我如何从 Cypress 的 i18n 中获取当前选择的语言呢?
我的LanguageSwitcher.vue组件(没有设置初始语言的逻辑)
</script>
<template>
<div data-testid="localeSwitcher">
<span v-if="getAvailableLocales().length > 1">
<span v-for="(locale, i) in getAvailableLocales()" :key="`locale-${locale}`">
<span v-if="i != 0" class="has-text-warning-dark"> | </span>
<a @click="setLocale(locale)" :class="[{ 'has-text-weight-bold' : ($i18n.locale === locale)}, 'has-text-warning-dark']">
{{ locale.toUpperCase() }}
</a>
</span>
</span>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
我的测试加载 i18n 并应该检查当前语言(但不知道如何做到这一点)
__test__/LanguageSwitcher.cy.js
import LanguageSwitcher from '../items/LanguageSwitcher.vue'
import { createI18n } from 'vue-i18n'
import { mount } from '@cypress/vue'
import en from '../../locales/en.json' …Run Code Online (Sandbox Code Playgroud) 在 Cypress 中,我在执行任何其他测试后更改了 Veu3 应用程序的视口,它给出了错误:“(未捕获的执行)TypeError a.value is null”。
产生错误的最小应用程序:
<script setup>
import { ref, onMounted } from 'vue'
const a = ref(null)
onMounted (() => {
function onWindowResize() {
window.addEventListener("resize", () => {
//a.value always needs to refresh when the window resizes to different content
a.value.textContent = 'Text displayed here will be decided on the window size'
})
}
onWindowResize()
})
</script>
<template>
<div>
<span ref="a" data-testid="test1">M</span>
<a> ..more</a>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
通过以下测试。这里需要注意的有趣的事情是,如果您不包含第一个测试,则不会出现错误。
import Test from '../Test.vue'
describe('run 2 test', () …Run Code Online (Sandbox Code Playgroud)