@localazy/strapi-plugin 0.1.4 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,7 @@
1
- # The Official Strapi Localization Plugin by Localazy
2
-
3
- ### The Official Strapi Localization Plugin by Localazy
1
+ ## The Official Strapi Localization Plugin by Localazy
4
2
 
5
3
  Strapi localization doesn't have to be a headache! Install the Strapi localization plugin and seamlessly translate your content into multiple languages with [Localazy](https://localazy.com).
6
4
 
7
- ![The Official Strapi Localization Plugin by Localazy](https://directus9.localazy.com/assets/e08d0418-5669-4255-9c2c-f5cc6e403edd)
8
-
9
5
  ### Manage your multilingual content with ease.
10
6
  1. [Sign up](https://localazy.com/register?ref=strapi_marketplace) & Upload your content to Localazy.
11
7
  2. Translate your content with machine translation assistance, or let the Localazy Continuous Localization Team translate your content for you. You can also quickly pre-translate everything in bulk or invite your translators.
@@ -13,15 +9,17 @@ Strapi localization doesn't have to be a headache! Install the Strapi localizati
13
9
 
14
10
  Learn more in the [Strapi + Localazy tutorial](https://localazy.com/blog/how-to-strapi-localization-with-localazy#getting-started-with-strapi-localization).
15
11
 
16
- ### General information
17
-
18
- This repository contains all the code needed to run the Strapi Localization Plugin by Localazy.
12
+ ## Setup
19
13
 
20
14
  ### Install plugin via NPM
21
15
 
22
16
  The plugin is available on [NPM](https://www.npmjs.com/package/@localazy/strapi-plugin).
23
17
  You can also follow the installation commands located in your Strapi project Marketplace. This is the recommended approach.
24
18
 
19
+ ```
20
+ npm install @localazy/strapi-plugin
21
+ ```
22
+
25
23
  ### Use plugin in a clean project locally
26
24
 
27
25
  Besides installing the plugin via `npm`, you can also use it in a project locally. Assuming you have a (clean) Strapi project set up, do:
@@ -47,12 +45,10 @@ module.exports = {
47
45
 
48
46
  5. Run the project. The plugin will be available in the admin.
49
47
 
50
- ### Tests
48
+ ## Tests
51
49
 
52
50
  To run tests, run `npm run test` command. To watch tests, run `npm run test:watch` command.
53
51
 
54
- In case you have an access, you might also want to check the README file located in development project root for more information on tests debugging.
55
-
56
- ### Support
52
+ ## Support
57
53
  - If you encounter any issues or have questions, please contact us at [team@localazy.com](mailto:team@localazy.com).
58
54
  - Join the [Localazy Discord](https://discord.gg/CAVhHrh) to discuss all things localization.
@@ -0,0 +1,102 @@
1
+ const { isoStrapiToLocalazy, isoLocalazyToStrapi } = require("../iso-locales-utils");
2
+
3
+ describe("iso-locales-utils.js", () => {
4
+ describe("transform Strapi ISO to Localazy ISO", () => {
5
+ it("should transform codes containing lang only", () => {
6
+ // setup
7
+ const input = ["en", "fr", "de", "es", "it", "ja", "ko", "pt", "ru", "zh"];
8
+
9
+ // execute
10
+ const output = input.map((item) => isoStrapiToLocalazy(item));
11
+
12
+ // verify
13
+ const expected = input;
14
+ expect(output).toEqual(expected);
15
+ });
16
+
17
+ it("should transform codes containing lang-region", () => {
18
+ // setup
19
+ const input = ["en-US", "fr-CA", "de-DE", "es-ES", "it-IT", "ja-JP", "ko-KR", "pt-BR", "ru-RU", "zh-CN"];
20
+
21
+ // execute
22
+ const output = input.map((item) => isoStrapiToLocalazy(item));
23
+
24
+ // verify
25
+ const expected = ["en_US", "fr_CA", "de_DE", "es_ES", "it_IT", "ja_JP", "ko_KR", "pt_BR", "ru_RU", "zh_CN"];
26
+ expect(output).toEqual(expected);
27
+ });
28
+
29
+ it("should transform codes containing lang-script", () => {
30
+ // setup
31
+ const input = ["en-Latn", "fr-Latn", "de-Latn", "es-Latn", "it-Latn", "ja-Latn", "ko-Latn", "pt-Latn", "ru-Latn", "zh-Latn"];
32
+
33
+ // execute
34
+ const output = input.map((item) => isoStrapiToLocalazy(item));
35
+
36
+ // verify
37
+ const expected = ["en#Latn", "fr#Latn", "de#Latn", "es#Latn", "it#Latn", "ja#Latn", "ko#Latn", "pt#Latn", "ru#Latn", "zh#Latn"];
38
+ expect(output).toEqual(expected);
39
+ });
40
+
41
+ it("should transform codes containing lang-script-region", () => {
42
+ // setup
43
+ const input = ["en-Latn-US", "fr-Latn-CA", "de-Latn-DE", "es-Latn-ES", "it-Latn-IT", "ja-Latn-JP", "ko-Latn-KR", "pt-Latn-BR", "ru-Latn-RU", "zh-Hant-CN"];
44
+
45
+ // execute
46
+ const output = input.map((item) => isoStrapiToLocalazy(item));
47
+
48
+ // verify
49
+ const expected = ["en_US#Latn", "fr_CA#Latn", "de_DE#Latn", "es_ES#Latn", "it_IT#Latn", "ja_JP#Latn", "ko_KR#Latn", "pt_BR#Latn", "ru_RU#Latn", "zh_CN#Hant"];
50
+ expect(output).toEqual(expected);
51
+ });
52
+ });
53
+
54
+ describe("transform Strapi ISO to Localazy ISO", () => {
55
+ it("should transform codes containing lang only", () => {
56
+ // setup
57
+ const input = ["en", "fr", "de", "es", "it", "ja", "ko", "pt", "ru", "zh"];
58
+
59
+ // execute
60
+ const output = input.map((item) => isoLocalazyToStrapi(item));
61
+
62
+ // verify
63
+ const expected = input;
64
+ expect(output).toEqual(expected);
65
+ });
66
+
67
+ it("should transform codes containing lang-region", () => {
68
+ // setup
69
+ const input = ["en_US", "fr_CA", "de_DE", "es_ES", "it_IT", "ja_JP", "ko_KR", "pt_BR", "ru_RU", "zh_CN"];
70
+
71
+ // execute
72
+ const output = input.map((item) => isoLocalazyToStrapi(item));
73
+
74
+ // verify
75
+ const expected = ["en-US", "fr-CA", "de-DE", "es-ES", "it-IT", "ja-JP", "ko-KR", "pt-BR", "ru-RU", "zh-CN"];
76
+ expect(output).toEqual(expected);
77
+ });
78
+
79
+ it("should transform codes containing lang-script", () => {
80
+ // setup
81
+ const input = ["en#Latn", "fr#Latn", "de#Latn", "es#Latn", "it#Latn", "ja#Latn", "ko#Latn", "pt#Latn", "ru#Latn", "zh#Latn"];
82
+
83
+ // execute
84
+ const output = input.map((item) => isoLocalazyToStrapi(item));
85
+
86
+ // verify
87
+ const expected = ["en-Latn", "fr-Latn", "de-Latn", "es-Latn", "it-Latn", "ja-Latn", "ko-Latn", "pt-Latn", "ru-Latn", "zh-Latn"];
88
+ expect(output).toEqual(expected);
89
+ });
90
+
91
+ it("should transform codes containing lang-script-region", () => {
92
+ // setup
93
+ const input = ["en_US#Latn", "fr_CA#Latn", "de_DE#Latn", "es_ES#Latn", "it_IT#Latn", "ja_JP#Latn", "ko_KR#Latn", "pt_BR#Latn", "ru_RU#Latn", "zh_CN#Hant"];
94
+
95
+ // execute
96
+ const output = input.map((item) => isoLocalazyToStrapi(item));
97
+ // verify
98
+ const expected = ["en-Latn-US", "fr-Latn-CA", "de-Latn-DE", "es-Latn-ES", "it-Latn-IT", "ja-Latn-JP", "ko-Latn-KR", "pt-Latn-BR", "ru-Latn-RU", "zh-Hant-CN"];
99
+ expect(output).toEqual(expected);
100
+ });
101
+ });
102
+ });
@@ -3,7 +3,31 @@ export const isoStrapiToLocalazy = (isoStrapi) => {
3
3
  return null;
4
4
  }
5
5
 
6
- return isoStrapi.replace("_", "-");
6
+ const split = isoStrapi.split("-");
7
+ const language = split[0];
8
+
9
+ const hasRegionAndScript = split.length === 3;
10
+
11
+ if (hasRegionAndScript) {
12
+ const script = split[1];
13
+ const region = split[2];
14
+
15
+ return `${language}_${region}#${script}`;
16
+ }
17
+
18
+ const hasPossiblyRegion = split.length === 2;
19
+
20
+ if (hasPossiblyRegion) {
21
+ const regionOrScript = split[1];
22
+
23
+ // is it script - the way Strapi resolves that
24
+ const isItRegion = regionOrScript.toUpperCase() === regionOrScript;
25
+
26
+ // it is region; otherwise it is script
27
+ return isItRegion ? `${language}_${regionOrScript}` : `${language}#${regionOrScript}`;
28
+ }
29
+
30
+ return isoStrapi.replace("-", "_");
7
31
  };
8
32
 
9
33
  export const isoLocalazyToStrapi = (isoLocalazy) => {
@@ -11,5 +35,24 @@ export const isoLocalazyToStrapi = (isoLocalazy) => {
11
35
  return null;
12
36
  }
13
37
 
14
- return isoLocalazy.replace("-", "_");
38
+ const scriptIndex = isoLocalazy.indexOf("#");
39
+ const hasScript = scriptIndex > -1;
40
+
41
+ if (hasScript) {
42
+ const script = isoLocalazy.substring(scriptIndex + 1);
43
+ const isoLocalazyWithoutScript = isoLocalazy.substring(0, scriptIndex);
44
+ const split = isoLocalazyWithoutScript.split("_");
45
+ const language = split[0];
46
+ const region = split[1];
47
+
48
+ if (!region) {
49
+ return `${language}-${script}`;
50
+ }
51
+
52
+ const isoStrapi = `${language}-${script}-${region.toUpperCase()}`;
53
+
54
+ return isoStrapi;
55
+ }
56
+
57
+ return isoLocalazy.replace("_", "-");
15
58
  };
@@ -115,7 +115,7 @@ function Download(props) {
115
115
  >
116
116
  <Divider />
117
117
  </Box>
118
- <Box marginTop={4}>
118
+ <Box marginTop={2}>
119
119
  <Flex gap="2">
120
120
  <Button variant="secondary" onClick={onTranslateInLocalazyClick}>
121
121
  {t("download.translate_in_localazy")}
@@ -49,11 +49,21 @@ function Login(props) {
49
49
  <HeaderLayout
50
50
  title={props.title}
51
51
  subtitle={props.subtitle}
52
- as="h2"
52
+ as="h1"
53
53
  />
54
54
  {props.isLoading && (<Loader>{t("common.loading_content")}</Loader>)}
55
55
  {!props.isLoading && (
56
- <Box paddingLeft={10}>
56
+ <Box
57
+ marginLeft={10}
58
+ marginRight={10}
59
+ background="neutral0"
60
+ paddingTop={6}
61
+ paddingRight={7}
62
+ paddingBottom={6}
63
+ paddingLeft={7}
64
+ hasRadius
65
+ shadow="tableShadow"
66
+ >
57
67
  <Box>
58
68
  <Typography variant="epsilon" textColor="neutral600">
59
69
  {t("common.localazy_plugin_description")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localazy/strapi-plugin",
3
- "version": "0.1.4",
3
+ "version": "0.1.7",
4
4
  "description": "The official Strapi Plugin by Localazy.",
5
5
  "strapi": {
6
6
  "name": "localazy",
@@ -52,8 +52,8 @@
52
52
  "jest": "^27.5.1"
53
53
  },
54
54
  "author": {
55
- "name": "David Vaclavek",
56
- "email": "david@localazy.com",
55
+ "name": "Localazy",
56
+ "email": "team@localazy.com",
57
57
  "url": "https://localazy.com"
58
58
  },
59
59
  "maintainers": [
@@ -2,8 +2,8 @@
2
2
 
3
3
  module.exports = {
4
4
  LOCALAZY_OAUTH_URL: "https://testing.localazy.com/oauth/authorize",
5
- LOCALAZY_OAUTH_APP_CLIENT_ID: "18503917571895066465",
6
- LOCALAZY_PLUGIN_CONNECTOR_API_URL: "http://localhost:3000",
5
+ LOCALAZY_OAUTH_APP_CLIENT_ID: "18503917571895066466",
6
+ LOCALAZY_PLUGIN_CONNECTOR_API_URL: "https://testing.localazy.com/plugin-connector",
7
7
  LOCALAZY_PUBLIC_API_URL: "https://testing.localazy.com/pubapi",
8
8
  LOCALAZY_PLUGIN_ID: "1",
9
9
  LOCALAZY_DEFAULT_FILE_NAME: "strapi.json",
@@ -25,7 +25,9 @@ module.exports = {
25
25
  const messageReport = [];
26
26
 
27
27
  // Strapi Service
28
- const StrapiService = strapi.plugin("localazy").service("strapiService");
28
+ const StrapiService = strapi
29
+ .plugin("localazy")
30
+ .service("strapiService");
29
31
 
30
32
  // Strapi i18n Service
31
33
  const StrapiI18nService = strapi
@@ -13,17 +13,18 @@ module.exports = ({ strapi }) => ({
13
13
  async createStrapiLocale(ctx, isoLocalazy) {
14
14
  try {
15
15
  const isoStrapi = isoLocalazyToStrapi(isoLocalazy);
16
- const localeName = intlDisplayName(isoLocalazy);
16
+ let localeName = intlDisplayName(isoStrapi);
17
17
 
18
18
  if (!localeName || !isoStrapi) {
19
19
  throw new Error("Invalid locale");
20
20
  }
21
+ localeName = `${localeName} (${isoStrapi})`;
21
22
 
22
23
  const newLocaleCtx = { ...ctx };
23
24
  newLocaleCtx.request.body = {
24
25
  isDefault: false,
25
26
  code: isoStrapi,
26
- name: localeName,
27
+ name: localeName.substring(0, 50), // limit name to 50 characters (given by Strapi)
27
28
  };
28
29
 
29
30
  await strapi
@@ -39,7 +40,6 @@ module.exports = ({ strapi }) => ({
39
40
  parseLocalazyKey(key) {
40
41
  const split = key.split(/\.|\[|\]/);
41
42
  const filteredSplit = split.filter((item) => item !== "");
42
- // return split;
43
43
 
44
44
  return {
45
45
  uid: `${filteredSplit[0]}.${filteredSplit[1]}`,
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ const { isoStrapiToLocalazy, isoLocalazyToStrapi } = require("../iso-locales-utils.js");
4
+
5
+ describe("iso-locales-utils.js", () => {
6
+ describe("transform Strapi ISO to Localazy ISO", () => {
7
+ it("should transform codes containing lang only", () => {
8
+ // setup
9
+ const input = ["en", "fr", "de", "es", "it", "ja", "ko", "pt", "ru", "zh"];
10
+
11
+ // execute
12
+ const output = input.map((item) => isoStrapiToLocalazy(item));
13
+
14
+ // verify
15
+ const expected = input;
16
+ expect(output).toEqual(expected);
17
+ });
18
+
19
+ it("should transform codes containing lang-region", () => {
20
+ // setup
21
+ const input = ["en-US", "fr-CA", "de-DE", "es-ES", "it-IT", "ja-JP", "ko-KR", "pt-BR", "ru-RU", "zh-CN"];
22
+
23
+ // execute
24
+ const output = input.map((item) => isoStrapiToLocalazy(item));
25
+
26
+ // verify
27
+ const expected = ["en_US", "fr_CA", "de_DE", "es_ES", "it_IT", "ja_JP", "ko_KR", "pt_BR", "ru_RU", "zh_CN"];
28
+ expect(output).toEqual(expected);
29
+ });
30
+
31
+ it("should transform codes containing lang-script", () => {
32
+ // setup
33
+ const input = ["en-Latn", "fr-Latn", "de-Latn", "es-Latn", "it-Latn", "ja-Latn", "ko-Latn", "pt-Latn", "ru-Latn", "zh-Latn"];
34
+
35
+ // execute
36
+ const output = input.map((item) => isoStrapiToLocalazy(item));
37
+
38
+ // verify
39
+ const expected = ["en#Latn", "fr#Latn", "de#Latn", "es#Latn", "it#Latn", "ja#Latn", "ko#Latn", "pt#Latn", "ru#Latn", "zh#Latn"];
40
+ expect(output).toEqual(expected);
41
+ });
42
+
43
+ it("should transform codes containing lang-script-region", () => {
44
+ // setup
45
+ const input = ["en-Latn-US", "fr-Latn-CA", "de-Latn-DE", "es-Latn-ES", "it-Latn-IT", "ja-Latn-JP", "ko-Latn-KR", "pt-Latn-BR", "ru-Latn-RU", "zh-Hant-CN"];
46
+
47
+ // execute
48
+ const output = input.map((item) => isoStrapiToLocalazy(item));
49
+
50
+ // verify
51
+ const expected = ["en_US#Latn", "fr_CA#Latn", "de_DE#Latn", "es_ES#Latn", "it_IT#Latn", "ja_JP#Latn", "ko_KR#Latn", "pt_BR#Latn", "ru_RU#Latn", "zh_CN#Hant"];
52
+ expect(output).toEqual(expected);
53
+ });
54
+ });
55
+
56
+ describe("transform Strapi ISO to Localazy ISO", () => {
57
+ it("should transform codes containing lang only", () => {
58
+ // setup
59
+ const input = ["en", "fr", "de", "es", "it", "ja", "ko", "pt", "ru", "zh"];
60
+
61
+ // execute
62
+ const output = input.map((item) => isoLocalazyToStrapi(item));
63
+
64
+ // verify
65
+ const expected = input;
66
+ expect(output).toEqual(expected);
67
+ });
68
+
69
+ it("should transform codes containing lang-region", () => {
70
+ // setup
71
+ const input = ["en_US", "fr_CA", "de_DE", "es_ES", "it_IT", "ja_JP", "ko_KR", "pt_BR", "ru_RU", "zh_CN"];
72
+
73
+ // execute
74
+ const output = input.map((item) => isoLocalazyToStrapi(item));
75
+
76
+ // verify
77
+ const expected = ["en-US", "fr-CA", "de-DE", "es-ES", "it-IT", "ja-JP", "ko-KR", "pt-BR", "ru-RU", "zh-CN"];
78
+ expect(output).toEqual(expected);
79
+ });
80
+
81
+ it("should transform codes containing lang-script", () => {
82
+ // setup
83
+ const input = ["en#Latn", "fr#Latn", "de#Latn", "es#Latn", "it#Latn", "ja#Latn", "ko#Latn", "pt#Latn", "ru#Latn", "zh#Latn"];
84
+
85
+ // execute
86
+ const output = input.map((item) => isoLocalazyToStrapi(item));
87
+
88
+ // verify
89
+ const expected = ["en-Latn", "fr-Latn", "de-Latn", "es-Latn", "it-Latn", "ja-Latn", "ko-Latn", "pt-Latn", "ru-Latn", "zh-Latn"];
90
+ expect(output).toEqual(expected);
91
+ });
92
+
93
+ it("should transform codes containing lang-script-region", () => {
94
+ // setup
95
+ const input = ["en_US#Latn", "fr_CA#Latn", "de_DE#Latn", "es_ES#Latn", "it_IT#Latn", "ja_JP#Latn", "ko_KR#Latn", "pt_BR#Latn", "ru_RU#Latn", "zh_CN#Hant"];
96
+
97
+ // execute
98
+ const output = input.map((item) => isoLocalazyToStrapi(item));
99
+ // verify
100
+ const expected = ["en-Latn-US", "fr-Latn-CA", "de-Latn-DE", "es-Latn-ES", "it-Latn-IT", "ja-Latn-JP", "ko-Latn-KR", "pt-Latn-BR", "ru-Latn-RU", "zh-Hant-CN"];
101
+ expect(output).toEqual(expected);
102
+ });
103
+ });
104
+ });
@@ -1,7 +1,4 @@
1
- const { isoStrapiToLocalazy } = require("./iso-locales-utils.js");
2
-
3
- module.exports = (isoCode) => {
4
- const isoDashed = isoStrapiToLocalazy(isoCode);
1
+ module.exports = (isoStrapi) => {
5
2
  let languageNames = new Intl.DisplayNames(["en"], { type: "language" });
6
- return languageNames.of(isoDashed);
3
+ return languageNames.of(isoStrapi);
7
4
  };
@@ -5,7 +5,28 @@ const isoStrapiToLocalazy = (isoStrapi) => {
5
5
  return null;
6
6
  }
7
7
 
8
- return isoStrapi.replace("_", "-");
8
+ const split = isoStrapi.split("-");
9
+ const language = split[0];
10
+
11
+ const hasRegionAndScript = split.length === 3;
12
+ if (hasRegionAndScript) {
13
+ const script = split[1];
14
+ const region = split[2];
15
+ return `${language}_${region}#${script}`;
16
+ }
17
+
18
+ const hasPossiblyRegion = split.length === 2;
19
+ if (hasPossiblyRegion) {
20
+ const regionOrScript = split[1];
21
+
22
+ // is it script - the way Strapi resolves that
23
+ const isItRegion = regionOrScript.toUpperCase() === regionOrScript;
24
+
25
+ // it is region; otherwise it is script
26
+ return isItRegion ? `${language}_${regionOrScript}` : `${language}#${regionOrScript}`;
27
+ }
28
+
29
+ return isoStrapi.replace("-", "_");
9
30
  };
10
31
 
11
32
  const isoLocalazyToStrapi = (isoLocalazy) => {
@@ -13,7 +34,24 @@ const isoLocalazyToStrapi = (isoLocalazy) => {
13
34
  return null;
14
35
  }
15
36
 
16
- return isoLocalazy.replace("-", "_");
37
+ const scriptIndex = isoLocalazy.indexOf("#");
38
+ const hasScript = scriptIndex > -1;
39
+ if (hasScript) {
40
+ const script = isoLocalazy.substring(scriptIndex + 1);
41
+ const isoLocalazyWithoutScript = isoLocalazy.substring(0, scriptIndex);
42
+ const split = isoLocalazyWithoutScript.split("_");
43
+ const language = split[0];
44
+ const region = split[1];
45
+
46
+ if (!region) {
47
+ return `${language}-${script}`;
48
+ }
49
+
50
+ const isoStrapi = `${language}-${script}-${region.toUpperCase()}`;
51
+ return isoStrapi;
52
+ }
53
+
54
+ return isoLocalazy.replace("_", "-");
17
55
  };
18
56
 
19
57
  module.exports = {