Um pacote vue.js que permite a localização de aplicativos da web.
Este pacote foi fortemente inspirado pelo Vue-Gtranslate.
Este pacote permite a localização de aplicativos da Web feitos com o VUE pelo uso do Google Translate. À medida que seu site e aplicativo aumentam, você pode encontrar uma necessidade de expandir para outros mercados fora do seu país de origem.
Se o seu mercado -alvo vive em todo o mar e falar um idioma diferente, você pode não ter nenhuma escolha a não ser localizar. No entanto, se essas pessoas puderem falar seu idioma, considere outros aspectos (culturais e/ou legais) para tomar uma decisão informada sobre se deve traduzir.
Para mais detalhes sobre o que é localização e os benefícios potenciais, consulte este artigo.
Para visualizar o pacote em ação, consulte -o no Code Sandbox.
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 >
Use em qualquer componente
import { Translator } from 'vue-google-translate';
< template >
< div >
< Translator />
< div >
</ template >
export default {
components: {
Translator
}
}
Passe uma variedade de países no seguinte formato
[
{
code : 'en|af' ,
title : 'Afrikaans' ,
} ,
{
code : 'en|ar' ,
title : 'Arabic' ,
} ,
{
code : 'en|ko' ,
title : 'Korean' ,
} ,
{
code : 'en|lt' ,
title : 'Lithuanian' ,
} ,
] ;
Uma lista completa dos idiomas padrão está na parte inferior deste documento. Se você deseja adicionar um novo idioma que não está na lista padrão, passe o novo idioma com e flagIconUrl
propriedade adicional da propriedade. Aqui está um bom lugar para obter esses ícones. Verifique se o código de tradução também é válido. Você pode obter os idiomas suportados e seus códigos deste site.
Além disso, você pode passar um texto alt como uma chave no objeto de tradução. Isso é útil para acessibilidade. Suas traduções personalizadas se pareceriam algo assim.
[
{
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' ,
} ,
] ;
Um evento emitiário opcional também está disponível como
< template >
< div >
< Translator @ on-country-click = " customEvent " : countries = " arrayOfCountries " />
</ div >
</ template >
Se desejar se livrar dos banners do Google, insira o seguinte CSS em um arquivo CSS global e importe esse arquivo nos seus arquivos main/index.js no 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' ,
} ,
] ;
O Vue-Google-Translate é um software de código aberto licenciado no MIT.