@servicensw/translate
v2.9.5
Published
Translate component
Downloads
390
Maintainers
Keywords
Readme
@servicensw/translate
Translate component that will translate an entire website using Googles Website translator service.
Service NSW package documentation and examples (Login credentials required)
Installation
npm install @servicensw/translate --save-dev
How to use
CSS
- PostCSS workflow:
@import '@servicensw/translate';
- Sass/Eyeglass:
@import 'servicensw-translate';
- Native CSS:
@import url('dist/translate.css');
- Link tag:
<link href="dist/translate.css" rel="stylesheet" type="text/css">
Vanilla JS
The recommended usage is of ES modules, to take advantage of code-splitting.
import Translate from "@servicensw/translate"
const translate = document.querySelectorAll(".translate:not(.is-excluded)")
translate.forEach((element, index) => {
new Translate(element, index)
})
Legacy usage;
- IIFE:
<script src="dist/translate.js" type="text/javascript"></script>
(initialized for all.translate
elements) - Common JS:
const Translate = require("@servicensw/translate")
(initialize yourself)
HTML
<div class="translate"></div>