vue google translate
1.0.0
VUE.JS軟件包,允許Web應用程序本地化。
該包裝受到Vue-Granslate的啟發。
該軟件包實現了通過使用Google Translate使用VUE製造的Web應用程序的本地化。隨著您的網站和應用程序的增長,您可能會發現需要擴展到本國以外的其他市場。
如果您的目標市場生活在海上並說另一種語言,那麼您可能別無選擇,只能本地化。但是,如果這些人能說您的語言,請考慮其他方面(文化和/或法律),以便就是否翻譯做出明智的決定。
有關哪些本地化和潛在好處的更多詳細信息,請查看本文。
要查看行動中的包裝,請在代碼沙箱中查看。
yarn add vue-google-translate
npm i vue-google-translate
//index.html
< head >
< script type =" text/javascript " >
function googleTranslateElementInit ( ) {
new google . translate . TranslateElement (
{ pageLanguage : 'en' , autoDisplay : false } ,
'app'
) ;
}
// app can be changed to the default id of your vue app available in App.vue or an id section of where
// you need translated
</ script >
< script
type =" text/javascript "
src =" https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit "
> </ script >
< script
type =" text/javascript "
src =" https://cdn.jsdelivr.net/gh/lewis-kori/vue-google-translate@main/src/utils/translatorRegex.js "
> </ script >
</ head >
在任何組件中使用
import { Translator } from 'vue-google-translate';
< template >
< div >
< Translator />
< div >
</ template >
export default {
components: {
Translator
}
}
以以下格式通過一系列國家
[
{
code : 'en|af' ,
title : 'Afrikaans' ,
} ,
{
code : 'en|ar' ,
title : 'Arabic' ,
} ,
{
code : 'en|ko' ,
title : 'Korean' ,
} ,
{
code : 'en|lt' ,
title : 'Lithuanian' ,
} ,
] ;
默認語言的完整列表在此文檔的底部。如果您想在默認列表中添加一個新語言,請通過新語言和其他屬性flagIconUrl
。這是採購這些圖標的好地方。確保翻譯代碼也是有效的。您可以從本網站獲取受支持的語言及其代碼。
此外,您可以將ALT文本作為翻譯對像中的鍵傳遞。這對於可訪問性很有用。您的自定義翻譯看起來像這樣。
[
{
code : 'en|iw' ,
title : 'Hebrew' ,
flagIconUrl : 'https://flagicons.lipis.dev/flags/4x3/il.svg' ,
altText : 'Hebrew language translation' ,
} ,
{
code : 'ga|pl' ,
title : 'Polish' ,
flagIconUrl : 'https://flagicons.lipis.dev/flags/4x3/pl.svg' ,
altText : 'Poland flag Icon' ,
} ,
] ;
可選的發射事件也可用於
< template >
< div >
< Translator @ on-country-click = " customEvent " : countries = " arrayOfCountries " />
</ div >
</ template >
如果您希望擺脫Google橫幅,請在全局CSS文件中插入以下CSS,然後將此文件導入您的主/index.js src
/* gets rid of the banner at the top of the page */
body {
top : 0 !important ;
}
/* get rids of the banner at the bottom of the web page */
. skiptranslate {
display : none !important ;
}
[
{
code : 'en|af' ,
title : 'Afrikaans' ,
} ,
{
code : 'en|sq' ,
title : 'Albanian' ,
} ,
{
code : 'en|ar' ,
title : 'Arabic' ,
} ,
{
code : 'en|hy' ,
title : 'Armenian' ,
} ,
{
code : 'en|az' ,
title : 'Azerbaijani' ,
} ,
{
code : 'en|eu' ,
title : 'Basque' ,
} ,
{
code : 'en|be' ,
title : 'Belarusian' ,
} ,
{
code : 'en|bg' ,
title : 'Bulgarian' ,
} ,
{
code : 'en|ca' ,
title : 'Catalan' ,
} ,
{
code : 'en|zh-CN' ,
title : 'Chinese (Simplified)' ,
} ,
{
code : 'en|zh-TW' ,
title : 'Chinese (Traditional)' ,
} ,
{
code : 'en|hr' ,
title : 'Croatian' ,
} ,
{
code : 'en|cs' ,
title : 'Czech' ,
} ,
{
code : 'en|da' ,
title : 'Danish' ,
} ,
{
code : 'en|nl' ,
title : 'Dutch' ,
} ,
{
code : 'en|en' ,
title : 'English' ,
} ,
{
code : 'en|et' ,
title : 'Estonian' ,
} ,
{
code : 'en|tl' ,
title : 'Filipino' ,
} ,
{
code : 'en|fi' ,
title : 'Finnish' ,
} ,
{
code : 'en|fr' ,
title : 'French' ,
} ,
{
code : 'en|de' ,
title : 'German' ,
} ,
{
code : 'en|el' ,
title : 'Greek' ,
} ,
{
code : 'en|hu' ,
title : 'Hungarian' ,
} ,
{
code : 'en|id' ,
title : 'Indonesian' ,
} ,
{
code : 'en|ga' ,
title : 'Irish' ,
} ,
{
code : 'en|it' ,
title : 'Italian' ,
} ,
{
code : 'en|ja' ,
title : 'Japanese' ,
} ,
{
code : 'en|ko' ,
title : 'Korean' ,
} ,
{
code : 'en|lt' ,
title : 'Lithuanian' ,
} ,
{
code : 'en|ms' ,
title : 'Malay' ,
} ,
{
code : 'en|no' ,
title : 'Norwegian' ,
} ,
{
code : 'en|pl' ,
title : 'Polish' ,
} ,
{
code : 'en|pt' ,
title : 'Portuguese' ,
} ,
{
code : 'en|ro' ,
title : 'Romanian' ,
} ,
{
code : 'en|ru' ,
title : 'Russian' ,
} ,
{
code : 'en|es' ,
title : 'Spanish' ,
} ,
{
code : 'en|sv' ,
title : 'Swedish' ,
} ,
{
code : 'en|th' ,
title : 'Thai' ,
} ,
{
code : 'en|tr' ,
title : 'Turkish' ,
} ,
{
code : 'en|uk' ,
title : 'Ukrainian' ,
} ,
] ;
Vue-Google-Translate是在MIT下許可的開源軟件。