Skip to content

Commit

Permalink
chore: minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
gustaveWPM committed May 19, 2024
1 parent 44bcd00 commit b717f1e
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 177 deletions.
74 changes: 39 additions & 35 deletions doc/blog/01.add-new-blog-category.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,22 @@ To do this, let's turn this:
// src/i18n/locales/fr.ts

// * ...
'blog-categories': {
'patch-notes': {
'_meta-description': 'Metadescription Notes de patch',
_title: 'Patch notes',
'discord-bot': {
'meta-description': 'Metadescription Patch-notes -> Bot Discord',
title: 'Discord Bot'
},
dashboard: {
'meta-description': 'Metadescription Patch-notes -> Dashboard',
title: 'Dashboard'
},
blog: {
'categories': {
'patch-notes': {
'_meta-description': 'Metadescription Notes de patch',
_title: 'Patch notes',
'discord-bot': {
'meta-description': 'Metadescription Patch-notes -> Bot Discord',
title: 'Discord Bot'
},
dashboard: {
'meta-description': 'Metadescription Patch-notes -> Dashboard',
title: 'Dashboard'
},
}
// * ...
}
// * ...
}
```

Expand All @@ -226,30 +228,32 @@ To this:
// * ... Added dummy-category related path segments
}
// * ...
'blog-categories': {
'dummy-category': {
'dummy-subcategory': {
'meta-description': 'Metadescription bidon -> sous-catégorie bidon',
title: 'Sous-catégorie bidon'
},
'_meta-description': 'Metadescription bidon',
_title: 'Catégorie bidon'
},
// * ... Added dummy-category i18n informations

'patch-notes': {
'_meta-description': 'Metadescription Notes de patch',
_title: 'Patch notes',
'discord-bot': {
'meta-description': 'Metadescription Patch-notes -> Bot Discord',
title: 'Discord Bot'
},
dashboard: {
'meta-description': 'Metadescription Patch-notes -> Dashboard',
title: 'Dashboard'
blog: {
'categories': {
'dummy-category': {
'dummy-subcategory': {
'meta-description': 'Metadescription bidon -> sous-catégorie bidon',
title: 'Sous-catégorie bidon'
},
'_meta-description': 'Metadescription bidon',
_title: 'Catégorie bidon'
},
// * ... Added dummy-category i18n informations

'patch-notes': {
'_meta-description': 'Metadescription Notes de patch',
_title: 'Patch notes',
'discord-bot': {
'meta-description': 'Metadescription Patch-notes -> Bot Discord',
title: 'Discord Bot'
},
dashboard: {
'meta-description': 'Metadescription Patch-notes -> Dashboard',
title: 'Dashboard'
},
}
// * ...
}
// * ...
}
```

Expand Down
5 changes: 4 additions & 1 deletion doc/i18n/00.quirks.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ For instance:

```ts
export default {
'blog-categories': blogCategories, // * ... Injecting autogenerated code
blog: {
categories: blogCategories // * ... Injecting autogenerated code
},
// * ...
'pages-titles': SHARED_VOCAB_SCHEMA['pages-titles'] // * ... Injecting code from our shared vocab schema definition
// * ...
} as const satisfies TypedLeafsJSONData<MaybeScanned>;
Expand Down
4 changes: 2 additions & 2 deletions doc/i18n/03.namespaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The left part is the alias, and the right part is the namespace from the diction
```ts
// config/i18n.ts
const _i18nsBase = {
blogCategories: 'blog-categories',
blog: 'blog',
pagesTitles: 'pages-titles',
dashboard: 'dashboard',
navbar: 'navbar',
Expand All @@ -43,7 +43,7 @@ For example:
```ts
// config/i18n.ts
const _i18nsBase = {
blogCategories: 'blog-categories',
blog: 'blog',
pagesTitles: 'pages-titles',
dashboard: 'dashboard',
navbar: 'navbar',
Expand Down
21 changes: 11 additions & 10 deletions interop/config/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,33 @@ export enum ELanguagesFlag {
}

const _i18nsBase = {
blogTagsFilters: 'blog-tags-filters',
metadescriptions: 'metadescriptions',
blogCategories: 'blog-categories',
blogAuthors: 'blog-authors',
pagesTitles: 'pages-titles',
searchMenu: 'search-menu',
dashboard: 'dashboard',
blogTags: 'blog-tags',
blogToc: 'blog-toc',
filters: 'filters',
navbar: 'navbar',
errors: 'errors',
infos: '_infos',
vocab: 'vocab',
blog: 'blog',
auth: 'auth'
} as const satisfies I18nsBase;

const i18nsBase: MakeI18nsBase<typeof _i18nsBase> = _i18nsBase;

export const i18ns = {
...i18nsBase,
brokenPagefindIntegrationError: 'errors.brokenPagefindIntegration',
dashboardPagesTitles: 'dashboard.pages-titles',
searchMenuOptions: 'search-menu.options',
searchMenuSrOnly: 'search-menu.sr-only',
srOnly: 'vocab.sr-only'
brokenPagefindIntegrationError: `${i18nsBase.errors}.brokenPagefindIntegration`,
dashboardPagesTitles: `${i18nsBase.dashboard}.pages-titles`,
searchMenuOptions: `${i18nsBase.searchMenu}.options`,
searchMenuSrOnly: `${i18nsBase.searchMenu}.sr-only`,
blogTagsFilters: `${i18nsBase.blog}.tags-filters`,
blogCategories: `${i18nsBase.blog}.categories`,
blogAuthors: `${i18nsBase.blog}.authors`,
srOnly: `${i18nsBase.vocab}.sr-only`,
blogTags: `${i18nsBase.blog}.tags`,
blogToc: `${i18nsBase.blog}.toc`
} as const satisfies Record<PropertyKey, I18nVocabScope> & typeof i18nsBase;

export const DEFAULT_LANGUAGE = DEFAULT_LANGUAGE_OBJ._infos.lng satisfies LanguageFlag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import type { Index } from 'packages/shared-types/src/Numbers';
import { BlogAuthorDuplicates, InvalidBlogAuthor, BULLET } from '../../../unifiedImport';

function validateAuthorNames<AuthorName extends string>(
tagsArrayUniq: AuthorName[],
indexedBlogTagOptions: Record<AuthorName, Index>,
blogTagOptions: readonly AuthorName[]
authorsNamesArrayUniq: AuthorName[],
indexedAuthorsNames: Record<AuthorName, Index>,
authorsNames: readonly AuthorName[]
): MaybeNull<InvalidBlogAuthor> {
const defects: string[] = [];

for (const tag of tagsArrayUniq) {
if (indexedBlogTagOptions[tag] === undefined) {
defects.push(tag);
for (const authorName of authorsNamesArrayUniq) {
if (indexedAuthorsNames[authorName] === undefined) {
defects.push(authorName);
continue;
}
}

// eslint-disable-next-line no-magic-numbers
if (defects.length > 0) return new InvalidBlogAuthor(defects, blogTagOptions);
if (defects.length > 0) return new InvalidBlogAuthor(defects, authorsNames);
return null;
}

Expand Down
105 changes: 54 additions & 51 deletions src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,69 @@ const SHARED: SharedVocabType = {
} as const;

export default {
// eslint-disable-next-line perfectionist/sort-objects
'blog-categories': {
'patch-notes-bis': {
'discord-bot-bis': {
'meta-description': 'Metadescription Patch-notes -> Bot Discord (bis)',
title: SHARED['pages-titles']['discord-bot-bis']
blog: {
categories: {
'patch-notes-bis': {
'discord-bot-bis': {
'meta-description': 'Metadescription Patch-notes -> Bot Discord (bis)',
title: SHARED['pages-titles']['discord-bot-bis']
},

'dashboard-bis': {
'meta-description': 'Metadescription Patch-notes -> Dashboard (bis)',
title: SHARED['pages-titles']['dashboard-bis']
},

'_meta-description': 'Metadescription Patch Notes (bis)',
_title: SHARED['pages-titles']['patch-notes-bis']
},

'dashboard-bis': {
'meta-description': 'Metadescription Patch-notes -> Dashboard (bis)',
title: SHARED['pages-titles']['dashboard-bis']
'patch-notes': {
'discord-bot': {
'meta-description': 'Patch-notes -> Discord Bot - Metadescription',
title: SHARED['pages-titles']['discord-bot']
},

dashboard: {
'meta-description': 'Patch-notes -> Dashboard - Metadescription',
title: SHARED['pages-titles'].dashboard
},

'_meta-description': 'Patch Notes Metadescription',
_title: SHARED['pages-titles']['patch-notes']
},

'_meta-description': 'Metadescription Patch Notes (bis)',
_title: SHARED['pages-titles']['patch-notes-bis']
'blog-testing-category': SHARED_TESTING_BLOG_CATEGORY_METADATAS
},

'patch-notes': {
'discord-bot': {
'meta-description': 'Patch-notes -> Discord Bot - Metadescription',
title: SHARED['pages-titles']['discord-bot']
},
toc: {
'sr-only': {
'hide-toc': `Hide the ${SHARED.vocab.toc}`,
'show-toc': `Show the ${SHARED.vocab.toc}`
}
},

tags: {
xylophone: 'Xylophone',
bagpipes: 'Bagpipes',
drums: 'Drums',
cello: 'Cello'
},

dashboard: {
'meta-description': 'Patch-notes -> Dashboard - Metadescription',
title: SHARED['pages-titles'].dashboard
authors: {
Gustave: {
bio: ''
},

'_meta-description': 'Patch Notes Metadescription',
_title: SHARED['pages-titles']['patch-notes']
Arnaud: {
bio: ''
}
},

'blog-testing-category': SHARED_TESTING_BLOG_CATEGORY_METADATAS
'tags-filters': {
'no-result-found': 'Nothing found!',
'clear-filters': 'Clear'
}
},

vocab: {
Expand Down Expand Up @@ -124,11 +154,13 @@ export default {
'next-screen': 'Next screen',
results: 'Search results'
},

options: {
blog: 'Search blog posts',
pages: 'Search pages',
all: 'Global search'
},

'nothing-found': 'Nothing found!'
},

Expand Down Expand Up @@ -160,35 +192,6 @@ export default {
}
},

'blog-toc': {
'sr-only': {
'hide-toc': `Hide the ${SHARED.vocab.toc}`,
'show-toc': `Show the ${SHARED.vocab.toc}`
}
},

'blog-tags': {
xylophone: 'Xylophone',
bagpipes: 'Bagpipes',
drums: 'Drums',
cello: 'Cello'
},

'blog-tags-filters': {
'no-result-found': 'Nothing found!',
'clear-filters': 'Clear'
},

'blog-authors': {
Gustave: {
bio: ''
},

Arnaud: {
bio: ''
}
},

auth: {
signup: SHARED.vocab['sign-up'],
logout: 'Logout',
Expand Down
Loading

0 comments on commit b717f1e

Please sign in to comment.