Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@sweetui/sweet-mobile
Advanced tools
Code
import { sweetI18n } from '@sweetui/sweet-mobile';
// 国际化
sweetI18n().then(i18n => {
// 初始化 App
const SweetApp = new Vue({
el: '#app',
render: c => c('app'),
...
// 注入i18n
i18n,
});
})
语言包分成3种情况
sweetI18n方法可提供一个参数,必须是Promise函数。Demo如下,用于从接口获取语言包
/* 模拟ajax请求 */
sweetI18n(() => {
return new Promise((resolve, reject) => {
const onlineDate = {
zh: { o: '哦哦哦' },
en: { o: 'OOO' },
}
setTimeout(() => {
resolve(onlineDate)
}, 100)
})
}).then(...)
// 真实ajax
sweetI18n(() =>{
return new Promise((resolve, reject) => {
this.SWTOOL.get('url').then(data => {
resolve(data)
}).catch(() => reject)
})
}).then(...)
注: 返回的data数据格式必须严格
const data ={
zh: { o: '哦哦哦' }, // zh => 语言lang 和 src/lang目录下的zh.js文件名保持一致
en: { o: 'OOO' },
}
app.config.js
文件 可配置language 设置初始语言。本地缓存SWEETLANG字段 > appConfig.language值 > navigator.language
setI18nLanguage
方法,用于切换lang语言包的方法,已注册到全局。this.$i18nLanguage(lang) // 调用
lang必须与@/lang/*目录下的文件名相同
语言包路径 @/lang/* 即 src/lang/* 例: lang=zh 对应 zh.js
基础定义
export default {
message: {
test: 'hello'
}
}
调用
{{$t("message.test")}} or <p v-html="$t('message.hello')"></p>
在某些情况下,您可能希望将翻译呈现为HTML邮件而不是静态字符串。
export default {
message: {
hello: 'hello <br> world'
}
}
模板如下:
<p v-html="$t('message.hello')"></p>
输出下面的内容(而不是预先格式化的信息)
<p>hello
<!--<br> exists but is rendered as html and not a string-->
world</p>
语言环境消息如下:
export default {
message: {
hello: '{msg} world'
}
}
模板如下:
<p>{{ $t('message.hello', { msg: 'hello' }) }}</p>
输出如下:
<p>hello world</p>
语言环境消息如下:
export default {
message: {
hello: '{0} world'
}
}
模板如下:
<p>{{ $t('message.hello', ['hello']) }}</p>
输出如下:
<p>hello world</p>
列表格式也接受类似数组的对象:
<p>{{ $t('message.hello', {'0': 'hello'}) }}</p>
输出如下:
<p>hello world</p>
语言环境消息如下:
export default {
message: {
hello: '%{msg} world'
}
}
模板如下:
<p>{{ $t('message.hello', { msg: 'hello' }) }}</p>
输出如下:
<p>hello world</p>
你可以翻译成复数形式。您必须定义具有管道|分隔符的区域设置,并在管道分隔符中定义复数形式。
语言环境消息如下:
export default {
car: 'car | cars',
apple: 'no apples | one apple | {count} apples'
}
模板如下:
<p>{{ $tc('car', 1) }}</p>
<p>{{ $tc('car', 2) }}</p>
<p>{{ $tc('apple', 0) }}</p>
<p>{{ $tc('apple', 1) }}</p>
<p>{{ $tc('apple', 10, { count: 10 }) }}</p>
输出如下:
<p>car</p>
<p>cars</p>
<p>no apples</p>
<p>one apple</p>
<p>10 apples</p>
FAQs
Sweet Mobile Core
The npm package @sweetui/sweet-mobile receives a total of 1 weekly downloads. As such, @sweetui/sweet-mobile popularity was classified as not popular.
We found that @sweetui/sweet-mobile demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.