Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@servicensw/translate

previousnext408MIT2.9.7

Translate component

readme

@servicensw/translate

Translate component that will translate an entire website using Googles Website translator service.

translate component

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>

Change log