Skip to main content

Javascript (Universal)

tip

We recommend using our CMS integrations (WordPress, Shopify, Squarespace etc...), if your provider is not supported, feel free to request it here

Our lightweight (<3kB) JavaScript library is compatible with modern web browsers, including but not limited to Google Chrome, Mozilla Firefox, Safari, and Microsoft Edge. You can either load the library directly from our CDN or import is as an NPM dependency.

Installation

Using our CDN

You can import the library on your site directly by loading this script

//cw.choose.wales/cw.min.js

We recommend including the as a script tag inside the <head> tag of all your pages to ensure it is ready as soon as possible

HTML Snippet
<script type="text/javascript" src="//cw.choose.wales/cw.min.js">

Using a package manager

Create a file at src/pages/my-react-page.js:

Run the following command to add our library in your project's dependencies:

npm install choose-wales --save

Once this is done, you can start using the npm package in your project:

Javascript
import chooseWales from 'choose-wales';

API

showUI

You can display the choose.wales widget using the showUI method

getPreference

setPreference

If you prefer to show your own user interface, you can use this method to store the user's preferred language