Skip to content

Commit 8377f95

Browse files
authored
feat: i18n support (#1881)
1 parent 464f055 commit 8377f95

File tree

77 files changed

+943
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+943
-184
lines changed

.eslintrc.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
MIT License
44
5-
Copyright (c) 2020 Looker Data Sciences, Inc.
5+
Copyright (c) 2021 Looker Data Sciences, Inc.
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal
@@ -24,13 +24,47 @@
2424
2525
*/
2626

27+
// eslint-disable-next-line @typescript-eslint/no-var-requires
28+
const ignoreProps = require('./config/i18nIgnoredProps.js')
29+
2730
module.exports = {
2831
extends: ['@looker/eslint-config', '@looker/eslint-config/license-header'],
2932
overrides: [
3033
{
3134
files: ['www/**/*.ts', 'www/**/*.tsx'],
3235
rules: {},
3336
},
37+
{
38+
files: ['packages/*/src/**/*.tsx', 'packages/*/src/**/*.ts'],
39+
rules: {
40+
'i18next/no-literal-string': [
41+
2,
42+
{
43+
ignoreAttribute: ignoreProps,
44+
ignoreComponent: ['HyphenWrapper', 'Icon', 'WarningIcon'],
45+
markupOnly: true,
46+
},
47+
],
48+
},
49+
},
50+
{
51+
files: [
52+
'*.test.*',
53+
'*.spec.*',
54+
'*.story.*',
55+
'*.js',
56+
'**/__mocks__/**',
57+
'**/stories/**',
58+
'packages/components-theme-editor/**',
59+
'packages/design-tokens/**',
60+
'packages/storybook-config/**',
61+
'www/**',
62+
'www/**',
63+
],
64+
rules: {
65+
'i18next/no-literal-string': 'off',
66+
},
67+
},
3468
],
3569
rules: {
3670
'@typescript-eslint/no-explicit-any': 'off',

.stylelintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
MIT License
44
5-
Copyright (c) 2020 Looker Data Sciences, Inc.
5+
Copyright (c) 2021 Looker Data Sciences, Inc.
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"flexbox",
2929
"focusable",
3030
"frontmatter",
31+
"haspopup",
3132
"labeledby",
3233
"labelledby",
3334
"nomarker",

__mocks__/i18next.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2021 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
const mock = {
27+
addResourceBundle: jest.fn(),
28+
changeLanguage: jest.fn(),
29+
init: jest.fn(() => Promise.resolve()),
30+
isInitialized: false,
31+
off: jest.fn(),
32+
on: jest.fn(),
33+
}
34+
35+
export default { ...mock, use: () => mock }

__mocks__/react-i18next.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2021 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
export const useTranslation = () => {
27+
return {
28+
t: (key: string, options: { [key: string]: string }) => {
29+
return `${key} ${
30+
options
31+
? Object.keys(options)
32+
.map((optionsKey) =>
33+
optionsKey === 'ns' ? '' : options[optionsKey]
34+
)
35+
.join(' ')
36+
: ''
37+
}`
38+
},
39+
}
40+
}
41+
42+
export const initReactI18next = jest.fn()

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
MIT License
44
5-
Copyright (c) 2020 Looker Data Sciences, Inc.
5+
Copyright (c) 2021 Looker Data Sciences, Inc.
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal

config/i18nIgnoredProps.js

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2021 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
const ours = [
28+
'icon',
29+
'iconBefore',
30+
'iconAfter',
31+
'gap',
32+
'grid-area',
33+
'textDecoration',
34+
]
35+
const aria = [
36+
'aria-autocomplete',
37+
'aria-haspopup',
38+
'aria-hidden',
39+
'aria-live',
40+
'aria-orientation',
41+
]
42+
const react = ['data-autofocus', 'data-testid', 'htmlFor']
43+
const styledComponents = ['as']
44+
const htmlXml = ['autoComplete', 'fill', 'role', 'xmlns']
45+
46+
const styledSystem = [
47+
'alignContent',
48+
'alignItems',
49+
'alignSelf',
50+
'background',
51+
'backgroundColor',
52+
'backgroundImage',
53+
'backgroundPosition',
54+
'backgroundRepeat',
55+
'backgroundSize',
56+
'bg',
57+
'bgImage',
58+
'bgPosition',
59+
'bgRepeat',
60+
'bgSize',
61+
'border',
62+
'borderBottom',
63+
'borderBottomColor',
64+
'borderBottomLeftRadius',
65+
'borderBottomRightRadius',
66+
'borderBottomStyle',
67+
'borderBottomWidth',
68+
'borderColor',
69+
'borderLeft',
70+
'borderLeftColor',
71+
'borderLeftStyle',
72+
'borderLeftWidth',
73+
'borderRadius',
74+
'borderRight',
75+
'borderRightColor',
76+
'borderRightStyle',
77+
'borderRightWidth',
78+
'borderStyle',
79+
'borderTop',
80+
'borderTopColor',
81+
'borderTopLeftRadius',
82+
'borderTopRightRadius',
83+
'borderTopStyle',
84+
'borderTopWidth',
85+
'borderWidth',
86+
'borderX',
87+
'borderY',
88+
'bottom',
89+
'boxShadow',
90+
'color',
91+
'display',
92+
'flex',
93+
'flexBasis',
94+
'flexDirection',
95+
'flexGrow',
96+
'flexShrink',
97+
'flexWrap',
98+
'fontFamily',
99+
'fontSize',
100+
'fontStyle',
101+
'fontWeight',
102+
'gridArea',
103+
'gridAutoColumns',
104+
'gridAutoFlow',
105+
'gridAutoRows',
106+
'gridColumn',
107+
'gridColumnGap',
108+
'gridGap',
109+
'gridRow',
110+
'gridRowGap',
111+
'gridTemplateAreas',
112+
'gridTemplateColumns',
113+
'gridTemplateRows',
114+
'height',
115+
'justifyContent',
116+
'justifyItems',
117+
'justifySelf',
118+
'left',
119+
'letterSpacing',
120+
'lineHeight',
121+
'm',
122+
'margin',
123+
'marginBottom',
124+
'marginLeft',
125+
'marginRight',
126+
'marginTop',
127+
'marginX',
128+
'marginY',
129+
'maxHeight',
130+
'maxWidth',
131+
'mb',
132+
'minHeight',
133+
'minWidth',
134+
'ml',
135+
'mr',
136+
'mt',
137+
'mx',
138+
'my',
139+
'opacity',
140+
'order',
141+
'overflow',
142+
'overflowX',
143+
'overflowY',
144+
'p',
145+
'padding',
146+
'paddingBottom',
147+
'paddingLeft',
148+
'paddingRight',
149+
'paddingTop',
150+
'paddingX',
151+
'paddingY',
152+
'pb',
153+
'pl',
154+
'position',
155+
'pr',
156+
'pt',
157+
'px',
158+
'py',
159+
'right',
160+
'size',
161+
'textAlign',
162+
'textShadow',
163+
'top',
164+
'verticalAlign',
165+
'width',
166+
'zIndex',
167+
]
168+
169+
module.exports = [
170+
...aria,
171+
...ours,
172+
...htmlXml,
173+
...react,
174+
...styledComponents,
175+
...styledSystem,
176+
]

config/jest/fileMock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
MIT License
44
5-
Copyright (c) 2020 Looker Data Sciences, Inc.
5+
Copyright (c) 2021 Looker Data Sciences, Inc.
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal

config/jest/styleMock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
MIT License
44
5-
Copyright (c) 2020 Looker Data Sciences, Inc.
5+
Copyright (c) 2021 Looker Data Sciences, Inc.
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal

jest-a11y.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
MIT License
44
5-
Copyright (c) 2020 Looker Data Sciences, Inc.
5+
Copyright (c) 2021 Looker Data Sciences, Inc.
66
77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)