linlinjava / litemall

又一个小商城。litemall = Spring Boot后端 + Vue管理员前端 + 微信小程序用户前端 + Vue用户移动端
MIT License
19.11k stars 7.17k forks source link

Translation (english + 中文) of the litemall-admin interface #541

Closed charlyisidore closed 1 year ago

charlyisidore commented 1 year ago

This pull request adds the ability to translate the admin interface using vue-i18n, and provides translations in english and chinese.

Changes in the code

Static text elements have been replaced by translatable keys as in the following examples:

Example 1:

<el-button @click="cancel">取消</el-button>

replaced by:

<el-button @click="cancel">{{ $t('app.button.cancel') }}</el-button>

Example 2:

<el-table-column align="center" label="商品ID" prop="id" />

replaced by:

<el-table-column align="center" :label="$t('goods_list.table.id')" prop="id" />

Translation files

The translation files are located in litemall-admin/src/locales. The translation keys follow the convention {page}.{context}.{description} (e.g. goods_list.table.id for the column '商品ID', in the table of the goods/list page). Many translations are redundant, but it might be relevant to keep them, because the translation might differ in some languages w.r.t. the context. Also, it is easy to merge them, but difficult to undo the merges.

Locale changer component

The user is able to change the current language thanks to the LocaleChanger component, added on the top-right corner of the login page. The component source is located in litemall-admin/src/components/LocaleChanger/index.vue, and can be reused anywhere.

Screenshots

Locale changer: litemall_login

litemall_dashboard

litemall_goods