Skip to content
This repository was archived by the owner on Oct 9, 2024. It is now read-only.

Commit 05d3713

Browse files
committed
Integrating localazy with UI LIibrary
1 parent 68bf7a1 commit 05d3713

16 files changed

+181
-75
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
LOCALAZY_READ_KEY=
2+
LOCALAZY_WRITE_KEY=

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
dist/*
22
src/stories/index.stories.js
3+
/src/lang/*.js
4+
!/src/lang/en.js
5+
!/src/lang/index.js
6+
!/src/lang/langs.js
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Upload translations
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
paths:
8+
- 'src/lang/en.js'
9+
10+
jobs:
11+
upload:
12+
name: Upload strings to Localazy
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v1
16+
- uses: localazy/upload@v1
17+
with:
18+
read_key: ${{ secrets.LOCALAZY_READ_KEY }}
19+
write_key: ${{ secrets.LOCALAZY_WRITE_KEY }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ npm-debug.log*
66
yarn-debug.log*
77
yarn-error.log*
88

9+
# local env files
10+
.env

build/translations.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-disable-next-line import/no-extraneous-dependencies */
2+
require('dotenv').config();
3+
const { exec } = require('child_process');
4+
5+
const readKey = process.env.LOCALAZY_READ_KEY;
6+
const writeKey = process.env.LOCALAZY_WRITE_KEY;
7+
8+
exec(`yarn run localazy download -r ${readKey} -w ${writeKey}`, (_, stdout) => {
9+
const files = Array.from(stdout.matchAll(/^File: file\.js \[([a-z]+)]$/gm))
10+
.filter((match) => match[1] !== 'en');
11+
console.log(
12+
`Downloaded ${files.length} languages. [${files.map((match) => match[1]).join(', ')}]`,
13+
);
14+
});

localazy.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"upload": {
3+
"type": "js",
4+
"files": {
5+
"pattern": "src/lang/*.js",
6+
"lang": "${autodetectLang}"
7+
}
8+
},
9+
"download": {
10+
"files": "src/lang/${lang}.js",
11+
"metadataFileJs": "src/lang/meta.js"
12+
}
13+
}

netlify.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Settings in the [build] context are global and are applied to all contexts
2+
[build]
3+
environment = { NODE_VERSION = "12.13.0" }

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616
"lint-scss": "stylelint \"src/**/*.scss\" \"src/**/*.vue\"",
1717
"lint-js:fix": "vue-cli-service lint --fix",
1818
"lint-scss:fix": "stylelint \"src/**/*.scss\" \"src/**/*.vue\" --fix",
19-
"build-lib": "vue-cli-service build --target lib --name ui-library src/index.js",
20-
"build": "vue-cli-service storybook:build -c config/storybook",
19+
"build-lib": "yarn translations:download && vue-cli-service build --target lib --name ui-library src/index.js",
20+
"build": "yarn translations:download && vue-cli-service storybook:build -c config/storybook",
2121
"storybook:build": "yarn build",
2222
"serve": "vue-cli-service storybook:serve -p 6006 -c config/storybook",
23+
"translations:download": "node build/translations.js",
2324
"storybook:serve": "yarn serve"
2425
},
2526
"dependencies": {
2627
"@chec/eslint-config": "^0.0.0",
2728
"@chec/stylelint-config": "^0.0.0",
29+
"@localazy/cli": "^1.2.3",
2830
"@popperjs/core": "^2.1.1",
2931
"@vue/eslint-config-airbnb": "^5.0.2",
3032
"autoprefixer": "^9.7.4",

src/lang/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.js

src/lang/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Internationalisation (i18n)
2+
3+
## Localazy integration
4+
5+
We use Localazy to manage translations of our dictionaries. If you haven't already been invited, you can gain access to
6+
the Localazy dashboard by asking in Slack. The English dictionary is automatically synced with Localazy on merges to
7+
staging, and the current translations are automatically downloaded from Localazy during the build process on Netlify.
8+
9+
### Testing translations locally
10+
11+
By default, translations are not part of the development build pipeline. You may use `yarn translations:download` to
12+
download them locally, but ensure that your .env file has read and write keys for Localazy - which you should be able
13+
to retrieve from the Localazy dashboard.

src/lang/en.js

+53-55
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,58 @@
11
export default {
2-
en: {
3-
accordion: {
4-
switchLabel: {
5-
open: 'Enabled',
6-
closed: 'Disabled',
7-
},
8-
toggleLabel: {
9-
open: 'Hide this section',
10-
closed: 'Show this section',
11-
},
2+
accordion: {
3+
switchLabel: {
4+
open: 'Enabled',
5+
closed: 'Disabled',
126
},
13-
general: {
14-
search: 'Search',
15-
// Appended to required form field labels
16-
requiredInline: '(required)',
17-
// Used after other statements, like in the case of filters: "Refunded: yes"
18-
yes: 'yes',
19-
},
20-
fileManager: {
21-
chooseFiles: 'Choose file(s)',
22-
deleteFile: 'Delete file',
23-
},
24-
filters: {
25-
apply: 'Apply filters',
26-
clear: 'Clear',
27-
filters: 'Filters',
28-
textSearch: 'Text search',
29-
},
30-
imageManager: {
31-
chooseImages: 'Choose image(s)',
32-
deleteImage: 'Delete image',
33-
},
34-
navigation: {
35-
returnToHome: 'Return to the home page',
36-
skip: 'Skip navigation',
37-
},
38-
paginate: {
39-
goToFirst: 'Go to the first page',
40-
goToNext: 'Go to the next page',
41-
goToPrevious: 'Go to the previous page',
42-
goToLast: 'Go to the last page',
43-
showing: 'Showing',
44-
of: '{x} of {y}',
45-
},
46-
tag: {
47-
dismiss: 'Dismiss',
48-
reset: 'Reset',
49-
},
50-
wysiwyg: {
51-
bold: 'Bold',
52-
italic: 'Italic',
53-
h1: 'Header 1',
54-
h2: 'Header 2',
55-
h3: 'Header 3',
56-
blockquote: 'Blockquote',
57-
bulletlist: 'Bullet list',
7+
toggleLabel: {
8+
open: 'Hide this section',
9+
closed: 'Show this section',
5810
},
5911
},
12+
general: {
13+
search: 'Search',
14+
// Appended to required form field labels
15+
requiredInline: '(required)',
16+
// Used after other statements, like in the case of filters: "Refunded: yes"
17+
yes: 'yes',
18+
},
19+
fileManager: {
20+
chooseFiles: 'Choose file(s)',
21+
deleteFile: 'Delete file',
22+
},
23+
filters: {
24+
apply: 'Apply filters',
25+
clear: 'Clear',
26+
filters: 'Filters',
27+
textSearch: 'Text search',
28+
},
29+
imageManager: {
30+
chooseImages: 'Choose image(s)',
31+
deleteImage: 'Delete image',
32+
},
33+
navigation: {
34+
returnToHome: 'Return to the home page',
35+
skip: 'Skip navigation',
36+
},
37+
paginate: {
38+
goToFirst: 'Go to the first page',
39+
goToNext: 'Go to the next page',
40+
goToPrevious: 'Go to the previous page',
41+
goToLast: 'Go to the last page',
42+
showing: 'Showing',
43+
of: '{x} of {y}',
44+
},
45+
tag: {
46+
dismiss: 'Dismiss',
47+
reset: 'Reset',
48+
},
49+
wysiwyg: {
50+
bold: 'Bold',
51+
italic: 'Italic',
52+
h1: 'Header 1',
53+
h2: 'Header 2',
54+
h3: 'Header 3',
55+
blockquote: 'Blockquote',
56+
bulletlist: 'Bullet list',
57+
},
6058
};

src/lang/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import en from './en';
2-
import pt from './pt';
1+
import langs from './langs';
32

43
export default {
5-
...en,
6-
...pt,
4+
...langs,
75
};

src/lang/langs.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Import metadata generated by localazy
2+
import meta from './meta';
3+
4+
// Do some webpack require magic to resolve files that are provided by localazy
5+
const requireModule = require.context('./', false, /\.js$/); //
6+
const langs = {};
7+
8+
meta.languages.forEach(({ language }) => {
9+
langs[language] = {
10+
...requireModule(`./${language}.js`).default,
11+
};
12+
});
13+
14+
export default langs;

src/lang/meta.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file is replaced by Localazy.
2+
export default {
3+
languages: [
4+
{
5+
language: 'en',
6+
},
7+
],
8+
};

src/lang/pt.js

-12
This file was deleted.

yarn.lock

+29-2
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,16 @@
12211221
"@types/istanbul-reports" "^1.1.1"
12221222
"@types/yargs" "^13.0.0"
12231223

1224+
"@localazy/cli@^1.2.3":
1225+
version "1.2.3"
1226+
resolved "https://registry.yarnpkg.com/@localazy/cli/-/cli-1.2.3.tgz#67edd21bd947b29d63a1e803ec7dc61103082cbc"
1227+
integrity sha512-ZeEj/iWVhr9J4WLa0fsYv7J1KC5l5itdY0mfT+c1dkaOjQuqDvip2EyLkkFpDGpXR59HppMbUwzH7oewyqGiGA==
1228+
dependencies:
1229+
abort-controller "3.0.0"
1230+
node-fetch "2.6.0"
1231+
text-encoding "0.7.0"
1232+
ws "6.2.1"
1233+
12241234
"@mdx-js/loader@^1.5.1":
12251235
version "1.6.6"
12261236
resolved "https://registry.yarnpkg.com/@mdx-js/loader/-/loader-1.6.6.tgz#de7438f3b18b097d66380f8698123a91c587a2f9"
@@ -2409,6 +2419,13 @@
24092419
resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
24102420
integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==
24112421

2422+
2423+
version "3.0.0"
2424+
resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392"
2425+
integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==
2426+
dependencies:
2427+
event-target-shim "^5.0.0"
2428+
24122429
accepts@~1.3.4, accepts@~1.3.5, accepts@~1.3.7:
24132430
version "1.3.7"
24142431
resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd"
@@ -5616,6 +5633,11 @@ [email protected]:
56165633
resolved "https://registry.yarnpkg.com/event-pubsub/-/event-pubsub-4.3.0.tgz#f68d816bc29f1ec02c539dc58c8dd40ce72cb36e"
56175634
integrity sha512-z7IyloorXvKbFx9Bpie2+vMJKKx1fH1EN5yiTfp8CiLOTptSYy1g8H4yDpGlEdshL1PBiFtBHepF2cNsqeEeFQ==
56185635

5636+
event-target-shim@^5.0.0:
5637+
version "5.0.1"
5638+
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"
5639+
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==
5640+
56195641
eventemitter3@^4.0.0:
56205642
version "4.0.4"
56215643
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.4.tgz#b5463ace635a083d018bdc7c917b4c5f10a85384"
@@ -8787,7 +8809,7 @@ node-emoji@^1.8.1:
87878809
dependencies:
87888810
lodash.toarray "^4.4.0"
87898811

8790-
node-fetch@^2.6.0:
8812+
node-fetch@2.6.0, node-fetch@^2.6.0:
87918813
version "2.6.0"
87928814
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
87938815
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
@@ -12557,6 +12579,11 @@ test-exclude@^5.2.3:
1255712579
read-pkg-up "^4.0.0"
1255812580
require-main-filename "^2.0.0"
1255912581

12582+
12583+
version "0.7.0"
12584+
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.7.0.tgz#f895e836e45990624086601798ea98e8f36ee643"
12585+
integrity sha512-oJQ3f1hrOnbRLOcwKz0Liq2IcrvDeZRHXhd9RgLrsT+DjWY/nty1Hi7v3dtkaEYbPYe0mUoOfzRrMwfXXwgPUA==
12586+
1256012587
[email protected], text-table@^0.2.0:
1256112588
version "0.2.0"
1256212589
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
@@ -13835,7 +13862,7 @@ [email protected]:
1383513862
dependencies:
1383613863
mkdirp "^0.5.1"
1383713864

13838-
ws@^6.0.0, ws@^6.2.1:
13865+
ws@6.2.1, ws@^6.0.0, ws@^6.2.1:
1383913866
version "6.2.1"
1384013867
resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.1.tgz#442fdf0a47ed64f59b6a5d8ff130f4748ed524fb"
1384113868
integrity sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==

0 commit comments

Comments
 (0)