Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Seyfarth committed Nov 12, 2023
2 parents 2c4854c + 9917ee9 commit 5b191e2
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 111 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,22 @@ import {switchLanguage, getSelectedLanguage} from 'weploy-translate';
Done. Now you should be able to switch the language manually.


### Translate Dynamic Dom Elements
### Disable auto translate on first time visit

If you want to translate dynamic dom elements you need to add the following code to the element you want to translate.
By default, weploy-translate will auto translate your website based on user's browser language on first time visit.


Coming soon...
If you want to disable auto translate on first time visit, you can pass `disableAutoTranslate: true` to the second argument of `getTranslations` function.
```javascript
useEffect(() => {
getTranslations("YOUR_API_KEY", {
disableAutoTranslate: true
});
}, []);
```
For script tag, you can add `data-disable-auto-translate="true"` attribute to the script tag
```html
<script src="https://unpkg.com/weploy-translate/dist/weploy-translate.js" data-weploy-key="YOUR_PROJECT_KEY" data-disable-auto-translate="true"></script>
```


### Custom timeout between route changes
Expand Down
4 changes: 3 additions & 1 deletion browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const { getTranslations, isBrowser, createLanguageSelect } = require("./index.js
if (isBrowser) {
const scriptTag = document.currentScript;
const apiKey = scriptTag.getAttribute("data-weploy-key");
getTranslations(apiKey);
const disableAutoTranslateAttr = scriptTag.getAttribute("data-disable-auto-translate")
const disableAutoTranslate = disableAutoTranslateAttr == "true";
getTranslations(apiKey, {disableAutoTranslate});
createLanguageSelect(apiKey);
}
Loading

0 comments on commit 5b191e2

Please sign in to comment.