Giter VIP home page Giter VIP logo

i7eo / google-translate-select Goto Github PK

View Code? Open in Web Editor NEW
365.0 33.0 85.0 2.22 MB

🚀 A modern, high-performance monorepo project designed with Google Translate JS SDK. Vue and react are supported!

Home Page: https://google-translate-select.i7eo.com

License: MIT License

JavaScript 8.95% TypeScript 33.40% HTML 0.43% Vue 40.27% XML 14.78% MDX 2.17%
vue translation i18n changesets monorepo react vite vue3

google-translate-select's Introduction

@google-translate-select

This project inherits from v-google-translate. The previous v-google-translate package move to branch backup/master, if you want to check it, click here.

GitHub Workflow Status (branch) All Contributors

@google-translate-select is an open-source project to invoke google translate jssdk to translate your dispaly content, we support vue2/vue3/react as follows:

GitHub package.json version (subfolder of monorepo) GitHub package.json version (subfolder of monorepo) GitHub package.json version (subfolder of monorepo)

Table of Contents

Refactor

I rewrote this project using pnpm + changeset + typescript + vite + tsup, use monorepo to manage project. The package name is @google-translate-select.

I refactor previous v-google-translate package using typescript and renamed it @google-translate-select/vue2, if you want to check it, click here.

Origin

This package enables localization of web apps made with vue by use of google translate.As your website and app grows, you may find a need to expand to other markets outside your home country.

If your target market lives across the sea and speaks a different language, you may not have any choice but to localize.

For more details on what localization is and the potential benefits, checkout this article.

Usage

Support Languages

see GOOGLE_TRANSLATE_SELECT_LANGUAGES in https://github.com/i7eo/google-translate-select/blob/master/packages/constants/src/web/languages.ts

Props

vue props see: https://github.com/i7eo/google-translate-select/blob/master/packages/vue3/src/types/props.ts

react props see: https://github.com/i7eo/google-translate-select/blob/master/packages/react/src/types/props.ts

Tips

  • Note that here we invoke translate.google.com/translate_a/element.js library file, the translation for the web pages of writing is the full amount. Only the translation of static content is supported without refreshing the page.

  • For something you don't want to translate, add class= "notranslate"

  • I can give you an example of best practices: We are working on a cross-border e-commerce project. In this project, we need two functions, multi-language and multi-currency, to complete internationalization. For the price on the page, we don't want to be translated into multiple languages. So we added class= "notranslate" to the price DOM to dynamically modify the price DOM information when the currency changes.

  • Google Translate JS SDK default your page source language is English (code is en), if your page source language is non-English language, please set defaultPageLanguageCode manually. For example: defaultPageLanguageCode = "zh-CN"

Inspire

This package was heavily inspired by vue-google-translate.

Development

For local development, in the root of the repo run pnpm i to install all dependencies and then pnpm build to build all packages. Now follow the instructions of the specific package you’re working on.

In case you are having problems to install the dependencies, try using NVM to get the same node version we use by running nvm use in the root of the repo, and check pnpm version.

Vitepress for @google-translate-select

We use vitepress with our library to develop document. You can start it from the root of the repo, just run pnpm dev:docs

Playground for @google-translate-select

We use vite with our library to test it. You can start it from the root of the repo, just run pnpm dev:react or pnpm dev:vue2 or pnpm dev:vue3.

Commits & releases

Use pnpm commit. This uses the cz-git CLI to create a conventional commit message based on your changes. CI is setup to release all new commits on the main branch that contains a new changeset.

Read more about changeset here

Get involved

PRs Welcome

We appreciate any help on our repositories. For more details about how to contribute to a package, see the README of the corresponding package.

Reach out to us

Create an issue using one of the templates File an issue. Make sure to remove any credential from your code before sharing it.

License

This repository is published under the MIT license.

Contributors

Thanks goes to these wonderful people (emoji key):

hyj
hyj

💻
suxiong
suxiong

💻
Chris Jones
Chris Jones

💻
Syamsoul Azrien Muda
Syamsoul Azrien Muda

💻
HuaZhuangNan
HuaZhuangNan

💻
Zero
Zero

📖

google-translate-select's People

Contributors

adamvindico avatar allcontributors[bot] avatar darknessmonarch avatar dependabot[bot] avatar huazhuangnan avatar i7eo avatar miracleh avatar rashidpathiyil avatar renovate[bot] avatar syamsoul avatar ubercj avatar yesux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-translate-select's Issues

🐛 Bug - TypeError: e(...).stop is not a function...

@google-translate-select bug report

Summary

image

Environment

The issu is located in two environments:

  • My local windows-mashine in dev.
  • My published site on Vercel

Steps to reproduce

  1. Create a nuxt3-starter-repo
  2. Create a component for GoogleTranslate. Link to my component on github.
  3. Create two nav-components, one for the top and one for the bottom.
  4. Load both in the same window or only bottom-nav in mobil etc.
  5. Load both of the nav-components on the same time (maybe this creates the error?).
  6. Load GoogleTranslate-component in both of the nav-components.
  7. Add a class to the element in bottom-nav with have the classname google-translate-select-dropdown__menu
// Example css-code
.drop-up-btn {
  top:-1000% !important;
  bottom: 100%
} 
// This is my very simple solution to make a popup.
  1. Add a script to add the drop-up-btn-class to the element.
// Example of javascript who also is acecpted as typescript
onMounted(() => {
  changeLanguage.count = 0 // debugging-tool
  function changeLanguage () {
    console.log('ChangeLanguage starting ... DropUpBtn clicked ' + changeLanguage.count)
    const dropUpBtn = document.getElementsByClassName('google-translate-select-dropdown__menu')[1]
    dropUpBtn.classList.add('drop-up-btn')
    changeLanguage.count = +1
  }
  const parentEl = document.getElementsByClassName('google-translate-select-dropdown__activator')[1]
  parentEl.setAttribute('id', 'dropUpBtn') // debugging-tool
  parentEl.addEventListener('click', changeLanguage)
})
console.log('FooterNav.vue finish loading.')

Comment

I will try to load only one of the nav-components at a time, to check if the error disappear.

Posting the result later in this week.

If someone will reproduce the error it is possibly to use this simple starter-kit and insert the GoogleTranslate-component to places on the index-page (instead of making two nav-components).

The error will show up only on click on the first select-button.

谷歌有离线语言包使用吗?

这个翻译在线的话,需要开启VPN才能正常翻译,但是大部分人是无法翻墙的,就用不了了,有什么解决方案么?

Nuxt Js

How can I use this library in nuxt js? It doesn't work for me.

🐛 Bug - Uncaught (in promise) TypeError: unref(...).stop is not a function

@google-translate-select bug report

Summary

When using this component with vue-router, when I hit the back button in the browser I'm getting the following error:
Uncaught (in promise) TypeError: unref(...).stop is not a function...google-translate-select.vue?vue&type=script&lang.ts:381

image

Environment & Usage

Using Vue3 and Chrome browser.

My component usage looks like so:

<template>
    <div class="border-b border-b-gray-200 pb-8">
        <h3 class="text-2xl text-primary pb-4 pl-1">
            <font-awesome-icon icon="fa-solid fa-comment" size="xl" class="text-primary"></font-awesome-icon>&nbsp;&nbsp;Translate
        </h3>
        <GoogleTranslateSelect
            default-language-code="en"
            default-page-language-code="en-GB"
            :fetch-browser-language="true"
            @select="handleGoogleTranslateSelect"
            class="border border-gray-400 rounded"
            trigger="click"
        />
    </div>
</template>

<script setup>
import GoogleTranslateSelect from '@google-translate-select/vue3'

const handleGoogleTranslateSelect = (language) => {

}
</script>

How to remove logo and show selected language code as code?

Hi @i7eo,

I am trying to get the outcode like the below picture:
Screenshot 2022-07-21 at 10 18 29 AM

the plugin is not allowing me to override the CSS:

For remove logo
div.eo__languages .eo__dropdown__menu .language .flag { background-image: none !important; }

I don't know how to show the dropdown selected option as language code.

Fragmented translation

The translation seems to be fragmented in most cases.

For instance, I'm trying to translate from Swedish (original) to Thai and get this:
"Det är öppet สำหรับ betatest-ansökningar"

So only 1 word in that sentence got translated.

Re-render translate by each language selected ago.

I just met a situation when I changed a lot of code of a language, then on another page it will translate according to each language I have selected before, then it will translate to the last language I have just selected. Don't know how to solve it. Tried to reload in @select, it reloads continuously.

🐛 Bug -

@google-translate-select bug report

Hebrew language doesn't display

When I click on the hebrew language in the dropdown nothing happens, the instruction remains on the original language or on the previously selected one.

Environment

Mozilla Firefox / Google Chrome

Steps to reproduce

Using the component and choosing the hebrew language

Expected results

The language displays well

Actual results

The language doesn't display

🐛 Bug - Translation only works partially

@google-translate-select bug report

Summary

When there is a long paragraph inside the page and the language is different from English the translation does not work correctly for several languages even if the defaultLanguageCode property of the component is correctly set.

Environment

  • Ubuntu 20.04
  • Mozilla Firefox / Google Chrome
  • Vue.js

Steps to reproduce

  • Write one or more long paragraphs in a language other than English on any html page.
  • Use de language selector for Vue.js and select any language other than English.

Example:

Original language: German
Target language: Arab

image

Expected results

  • The selected language is correctly displayed in the interface consistently.

Actual results

  • Some languages do not work when selected and the some paragraphs are partially translated

🐛 Bug - type error in nextjs 14.2.4

@google-translate-select bug report

Summary

this is the type error am getting when i run it on nextjs

Screenshot 2024-08-19 042512

TypeError: (0 , index3_mjs__WEBPACK_IMPORTED_MODULE_3_.jsx) is not a function

Environment

Next.js 14.2.4

I tested using both chrome and brave but it safe to assume that the problem is simply next.js

Steps to reproduce

  1. install on nextjs
npm install npm install @google-translate-select/react
  1. import and use it
"use client"


import GoogleTranslateSelect from "@google-translate-select/react";
 
export default test = () => {
return (
  <div>
          <GoogleTranslateSelect
            defaultLanguageCode="en"
            defaultPageLanguageCode="en"
            fetchBrowserLanguage={false}
            trigger="click"
            select={handleGoogleTranslateSelect}
          />
        </div>
);
}
  1. Run it
npm run dev

Expected results

to work like how it works on the projects i have used on vue

Actual results

Screenshot 2024-08-19 042512

我找到个解决方法,你看下行不行

把这个请求地址换一下就好了
image

之前是“//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit”
换成“//translate.google.cn/translate_a/element.js?cb=googleTranslateElementInit”

把com换成cn,**就能访问

image

我试了一下是可以的,但是又遇到另外一个问题,这个supportedLanguages加载失败,我换成.cn之后是可以访问到资源的,但是没有找到这个是在哪里调的接口。

这个代码如果是你写的话,我觉得你可以优化优化,这样国内的兄弟们就能用了,万分感谢。

ps:我现在是把你的组件移植到我的components下面使用的。

望回复,谢谢!

💡 请问有方式隐藏翻译的加载动画吗?

@google-translate-select contribution proposal

The problem

  • 遇到的问题: 加载的 spinner 不会消失(无限循环)
  • 影响: 会导致左上返回按钮被阻挡无法返回
  • 触发时机: 未知
  • 版本: "@google-translate-select/vue3": "^0.1.0"

css

spinner html

The proposed solution

透过 props 隐藏 spinner 动画

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update dependency jsdom to v22
  • chore(deps): update dependency postcss-preset-env to v9
  • chore(deps): update dependency rimraf to v5
  • chore(deps): update dependency tsup to v7
  • chore(deps): update dependency typescript to v5
  • chore(deps): update dependency vite to v4
  • chore(deps): update dependency vite-plugin-dts to v3
  • chore(deps): update pnpm to v8
  • fix(deps): update dependency prettier to v3
  • fix(deps): update dependency stylelint-config-recommended to v13
  • fix(deps): update dependency stylelint-config-recommended-scss to v12
  • fix(deps): update dependency stylelint-config-standard to v34
  • fix(deps): update dependency stylelint-config-standard-scss to v10
  • fix(deps): update dependency stylelint-order to v6
  • fix(deps): update dependency vue to v3

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/auto-approve.yml
  • hmarr/auto-approve-action v2
.github/workflows/release.yml
  • actions/checkout v3
  • pnpm/action-setup v2
  • actions/setup-node v3
.github/workflows/stale.yml
  • actions/stale v7
npm
apps/docs/package.json
  • vitepress 1.0.0-alpha.35
apps/playground-react/package.json
  • react ^18.2.0
  • react-dom ^18.2.0
  • @types/react ^18.0.24
  • @types/react-dom ^18.0.8
  • @vitejs/plugin-react ^3.0.0
  • sass ^1.56.1
  • typescript ^4.8.4
  • vite ^4.0.1
apps/playground-vue2/package.json
  • vue 2.6.11
  • sass ^1.56.1
  • terser 5.4.0
  • typescript ^4.8.4
  • vite ^3.0.0
  • vite-plugin-vue2 ^2.0.2
  • vue-template-compiler 2.6.11
apps/playground-vue3/package.json
  • vue ^3.2.41
  • @vitejs/plugin-vue ^4.0.0
  • typescript ^4.8.4
  • vite ^4.0.1
internals/commitlint-config/package.json
  • @commitlint/cli 17.2.0
  • @commitlint/config-conventional 17.2.0
  • @types/node *
  • czg ^1.3.12
internals/eslint-config/package.json
  • @typescript-eslint/eslint-plugin ^5.42.0
  • @typescript-eslint/parser ^5.42.0
  • eslint-config-prettier ^8.5.0
  • eslint-plugin-eslint-comments ^3.2.0
  • eslint-plugin-import ^2.26.0
  • eslint-plugin-jsonc ^2.5.0
  • eslint-plugin-markdown ^3.0.0
  • eslint-plugin-prettier ^4.2.1
  • eslint-plugin-vue ^9.7.0
  • jsonc-eslint-parser ^2.1.0
  • prettier ^2.7.1
  • yaml-eslint-parser ^1.1.0
  • eslint ^8.25.0
  • typescript ^4.8.4
internals/lint-staged-config/package.json
  • lint-staged ^13.0.3
internals/prettier-config/package.json
  • prettier ^2.7.1
internals/simple-git-hooks-config/package.json
  • simple-git-hooks ^2.8.1
internals/stylelint-config/package.json
  • postcss ^8.4.18
  • postcss-html ^1.5.0
  • postcss-scss 4.0.5
  • stylelint-config-prettier ^9.0.3
  • stylelint-config-recommended ^9.0.0
  • stylelint-config-recommended-scss 8.0.0
  • stylelint-config-recommended-vue ^1.4.0
  • stylelint-config-standard ^29.0.0
  • stylelint-config-standard-scss 6.1.0
  • stylelint-order ^5.0.0
  • stylelint ^14.14.1
internals/ts-config/package.json
package.json
  • @changesets/assemble-release-plan ^5.2.3
  • @changesets/changelog-github ^0.4.8
  • @changesets/cli ^2.26.0
  • @changesets/config ^2.3.0
  • @changesets/pre ^1.0.14
  • @changesets/read ^0.5.9
  • @changesets/types ^5.2.1
  • @manypkg/get-packages 1.1.3
  • @types/inquirer 9.0.3
  • @types/jsdom 20.0.1
  • @types/node *
  • @types/prettier ^2.7.2
  • @types/semver 7.3.13
  • @vitest/ui ^0.26.2
  • inquirer ^9.1.4
  • jsdom ^20.0.2
  • npm-run-all ^4.1.5
  • octokit ^2.0.10
  • rimraf ^3.0.2
  • semver ^7.3.8
  • tsx ^3.11.0
  • turbo ^1.6.3
  • typescript ^4.8.4
  • vitest ^0.26.2
  • pnpm 7.18.0
packages/constants/package.json
  • tsup ^6.4.0
  • typescript ^4.8.4
packages/react/package.json
  • classnames 2.3.2
  • react ^18.2.0
  • react-dom ^18.2.0
  • @types/react ^18.0.24
  • @types/react-dom ^18.0.8
  • @vitejs/plugin-legacy 3.0.1
  • @vitejs/plugin-react ^3.0.0
  • terser 5.4.0
  • tsup ^6.4.0
  • typescript ^4.8.4
  • vite ^4.0.1
  • vite-plugin-css-injected-by-js 2.1.1
  • vite-plugin-dts ^1.7.0
packages/theme-chalk/package.json
  • @types/clean-css ^4.2.6
  • @types/gulp 4.0.10
  • @types/postcss-preset-env ^7.7.0
  • autoprefixer ^10.4.13
  • chalk ^5.1.2
  • clean-css ^5.3.1
  • consola ^2.15.3
  • esbuild 0.15.13
  • esbuild-plugin-copy 2.0.1
  • esbuild-sass-plugin ^2.4.0
  • postcss ^8.4.19
  • postcss-preset-env ^7.8.2
  • sass ^1.56.1
  • tsup ^6.4.0
packages/utils/package.json
  • tsup ^6.4.0
  • typescript ^4.8.4
packages/vue2/package.json
  • vue 2.6.11
  • sass ^1.56.1
  • terser 5.4.0
  • typescript ^4.8.4
  • vite ^4.0.1
  • vite-plugin-css-injected-by-js 2.1.1
  • vite-plugin-dts ^1.7.0
  • vite-plugin-vue2 ^2.0.2
  • vue-template-compiler 2.6.11
packages/vue3/package.json
  • vue ^3.2.41
  • @vitejs/plugin-vue ^4.0.0
  • @vitejs/plugin-vue-jsx ^3.0.0
  • @vue/test-utils 2.2.4
  • sass ^1.56.1
  • typescript ^4.8.4
  • vite ^4.0.1
  • vite-plugin-css-injected-by-js 2.1.1
  • vite-plugin-dts ^1.7.0

  • Check this box to trigger a request for Renovate to run again on this repository

可以支持下 Vue3 吗?

这个项目非常好用, 但无奈我是后端开发, 没有能力修改此项目支持 Vue3, 希望作者可以支持下

🐛 Bug - [Vue warn]: Error in v-on handler: "TypeError: Cannot read properties of null (reading 'options')"

@google-translate-select bug report

I sometimes get this error when I click on a dropdown language option. This only happens after I navigate away from the page the component is mounted on and when I switch back to the page and try again it doesn't work. I assume the component options aren't ready yet by the rime it's mounted?

Summary

Environment

Using Vue 2.7

Steps to reproduce

Expected results

To switch to the language clicked on the dropdown

Actual results

The language switch doesn't work because of this error

refactor: for vue3.x

  1. 单独建一个分支(repo:next)专门提供给vue3使用

  2. 使用 monorepo 分别管理vue2、vue3的包(完全替换当前repo:master代码)

  3. 使用 vue-demi 兼容 vue2、vue3写法(完全替换当前repo:master代码)

#15 #22

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Location: .github/renovate.json
Error type: The renovate configuration file contains some invalid settings
Message: Invalid configuration option: node

🐛 Bug - 内容经过翻译后 computed属性不能正常被修改

说实话,我也不知道这是不能翻译还是bug,不过还是想提一下的。

image

这是codesand复现的地址:https://codesandbox.io/s/v-google-translate-demo-forked-pnv53v?file=/src/App.vue

就是谷歌翻译完之后,点击添加价格的按钮,数量就不会再发生任何变化了。下面添加了 notranslate 的类的价格,倒是发生了变化

我看npm上面 v-google-translate 是链到了这个库来着,所以我就直接在这里提了

Regarding style issues

The style of this plug-in is too restrictive, and it does not provide incoming style modification. If you want to modify it, you need to make intrusive style modification. It doesn't feel perfect. If you can provide a way to pass parameters, you can customize the style. In this case, it can be more handy to use

💡 Proposal - Programmatically translate?

If you have some dynamic content, would it be nice to expose the triggerTranslate method to translate the content or basically a way to re-trigger the translation apart from clicking the dopdown

💡 Proposal - Adding in an extra language

@google-translate-select contribution proposal

The problem

Hi there, I was hoping to add in Welsh as an extra language to the below, please:
packages/constants/src/web/languages.ts

The proposed solution

export const GOOGLE_TRANSLATE_SELECT_LANGUAGES_CODES = [
'cy',
] as const
export const GOOGLE_TRANSLATE_SELECT_LANGUAGES: Language[] = [
  {
    code: 'cy',
    name: 'Welsh',
    cname: '威尔士语',
    ename: 'Welsh',
  },
]

How to set language dynamically?

Hi @i7eo ,
I wanted to set the Chinese language by default when users log in to the platform.
Example:
<v-google-translate defaultLanguageCode="ar"></v-google-translate>
While implementing the above code initially it shows the Arabian language then after the page loads, it is set to English. Any clue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.