Skip to content

Commit 80b13fa

Browse files
author
hugur
committed
upgrade string/locale cms collection to utility functions
1 parent af43e54 commit 80b13fa

File tree

6 files changed

+71
-61
lines changed

6 files changed

+71
-61
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"Hello": "Hello",
33
"404.title": "404: Not found",
4-
"404.message": "You just hit a route that doesn't exist... sadness doesn't exist only suffering does",
5-
"posts.title": "Blog",
6-
"tags.title": "Tags"
4+
"404.message": "You just hit a route that doesn't exist... sadness doesn't exist only suffering does"
75
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {buildLocalesCollection} from '@w3f/gatsby-theme-w3f/src/cms/collections/locales.js';
2+
import translations from '../../../content/locales/en/translations.json';
3+
4+
const stringFiles = [
5+
{
6+
name: 'translations',
7+
strings: translations,
8+
}
9+
]
10+
const locales = buildLocalesCollection(stringFiles);
11+
12+
export default locales

example/src/cms/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ import options from "./options";
77
const netlifyCmsGitLocal = process.env.GATSBY_NETLIFY_CMS_GIT_LOCAL === "true";
88

99
if (netlifyCmsGitLocal) {
10-
options.config.local_backend = true;
11-
options.config.backend = {
12-
name: "git-gateway",
13-
};
10+
options.config.local_backend = true;
11+
options.config.backend = {
12+
name: "git-gateway",
13+
};
14+
} else {
15+
// in a real project, use a real backend
16+
options.config.backend = {
17+
name: 'github',
18+
repo: 'organisation/project-repo',
19+
branch: 'main',
20+
auth_scope: 'repo',
21+
open_authoring: true,
22+
use_graphql: true,
23+
};
1424
}
1525

16-
// in a real project, use a real backend
17-
/* options.config.backend = {
18-
* name: 'github',
19-
* repo: 'organisation/project-repo',
20-
* branch: 'main',
21-
* auth_scope: 'repo',
22-
* open_authoring: true,
23-
* use_graphql: true,
24-
* }; */
25-
2626
/* initialize the CMS editor-components*/
2727
CMS.registerEditorComponent(LinkCTA);
2828

example/src/cms/options.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
/* theme collections */
2-
import strings from '@w3f/gatsby-theme-w3f/src/cms/collections/strings';
1+
import locales from './collections/locales.js';
32

4-
const collections = [strings]
3+
const collections = [locales]
54

65
const cmsOptions = {
7-
config: {
8-
collections: collections,
9-
display_url: window.location.origin,
10-
publish_mode: 'editorial_workflow',
6+
config: {
7+
collections,
8+
display_url: window.location.origin,
119

12-
// both folder values, are overwritten
13-
// by some local collections config
14-
media_folder: '/content/media',
15-
public_folder: '/public',
10+
// both folder values, are overwritten
11+
// by some local collections config
12+
media_folder: '/content/media',
13+
public_folder: '/public',
1614

17-
// re-defined in ./index.js, from env (for local backend)
18-
backend: {
19-
name: 'test-repo',
20-
branch: 'main',
15+
// re-defined in ./index.js, from env (for local backend)
16+
backend: {
17+
name: 'test-repo',
18+
branch: 'main',
19+
},
2120
},
22-
},
2321
};
2422

2523
export default cmsOptions;
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
import strings from './strings';
1+
import translations from '../../../content/locales/en/translations.json';
2+
import {buildLocalesCollection} from './locales';
3+
4+
const stringFiles = [
5+
{
6+
name: 'translations',
7+
strings: translations,
8+
}
9+
]
10+
const locales = buildLocalesCollection(stringFiles);
211

312
export default {
4-
strings
13+
locales
514
};
Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import translations from '../../../content/locales/en/translations.json';
2-
3-
/* model-strings is the model responsible for english (en) language strings */
4-
5-
/* List of file names (without .json extension)
1+
/* `stringFiles`: list of file names (without .json extension)
62
* and the object with all language strings */
7-
const stringFiles = [
8-
{
9-
name: 'translations',
10-
strings: translations,
11-
},
12-
];
13-
3+
const buildLocalesCollection = (stringFiles) => {
4+
/* generate the files list and their fields
5+
from the string in json files */
6+
const strings = {
7+
name: 'configs',
8+
label: 'Locales',
9+
delete: false,
10+
editor: {
11+
preview: false,
12+
},
13+
files: buildFiles(stringFiles),
14+
description:
15+
'Strings of text, which `value` is used to replace the `key` in the site; with the different equivalent in languages. Here is only the english content. These values are the bits of text that are not part of other content types in the cms.',
16+
};
17+
return strings;
18+
}
1419
/* methods to build files and fields */
1520
const buildFiles = files => {
1621
return files.map(file => {
@@ -32,18 +37,6 @@ const buildFields = fieldsJson => {
3237
});
3338
};
3439

35-
/* generate the files list and their fields
36-
from the string in json files */
37-
const strings = {
38-
name: 'configs',
39-
label: 'Strings',
40-
delete: false,
41-
editor: {
42-
preview: false,
43-
},
44-
files: buildFiles(stringFiles),
45-
description:
46-
'Strings of text, which `value` is used to replace the `key` in the site; with the different equivalent in languages. Here is only the english content. These values are the bits of text that are not part of other content types in the cms.',
40+
export {
41+
buildLocalesCollection
4742
};
48-
49-
export default strings;

0 commit comments

Comments
 (0)