chore: re-exports languages in payload (#5771)
This commit is contained in:
@@ -19,7 +19,9 @@ export const getRequestLanguage = ({
|
||||
}: GetRequestLanguageArgs): AcceptedLanguages => {
|
||||
const langCookie = cookies.get(`${config.cookiePrefix || 'payload'}-lng`)
|
||||
const languageFromCookie = typeof langCookie === 'string' ? langCookie : langCookie?.value
|
||||
const languageFromHeader = extractHeaderLanguage(headers.get('Accept-Language'))
|
||||
const languageFromHeader = headers.get('Accept-Language')
|
||||
? extractHeaderLanguage(headers.get('Accept-Language'))
|
||||
: undefined
|
||||
const fallbackLang = config?.i18n?.fallbackLanguage || defaultLanguage
|
||||
|
||||
const supportedLanguageKeys = Object.keys(config?.i18n?.supportedLanguages || {})
|
||||
|
||||
1
packages/payload/src/exports/i18n/ar.ts
Normal file
1
packages/payload/src/exports/i18n/ar.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { ar } from '@payloadcms/translations/languages/ar'
|
||||
1
packages/payload/src/exports/i18n/az.ts
Normal file
1
packages/payload/src/exports/i18n/az.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { az } from '@payloadcms/translations/languages/az'
|
||||
1
packages/payload/src/exports/i18n/bg.ts
Normal file
1
packages/payload/src/exports/i18n/bg.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { bg } from '@payloadcms/translations/languages/bg'
|
||||
1
packages/payload/src/exports/i18n/cs.ts
Normal file
1
packages/payload/src/exports/i18n/cs.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { cs } from '@payloadcms/translations/languages/cs'
|
||||
1
packages/payload/src/exports/i18n/de.ts
Normal file
1
packages/payload/src/exports/i18n/de.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { de } from '@payloadcms/translations/languages/de'
|
||||
1
packages/payload/src/exports/i18n/en.ts
Normal file
1
packages/payload/src/exports/i18n/en.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { en } from '@payloadcms/translations/languages/en'
|
||||
1
packages/payload/src/exports/i18n/es.ts
Normal file
1
packages/payload/src/exports/i18n/es.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { es } from '@payloadcms/translations/languages/es'
|
||||
1
packages/payload/src/exports/i18n/fa.ts
Normal file
1
packages/payload/src/exports/i18n/fa.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { fa } from '@payloadcms/translations/languages/fa'
|
||||
1
packages/payload/src/exports/i18n/fr.ts
Normal file
1
packages/payload/src/exports/i18n/fr.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { fr } from '@payloadcms/translations/languages/fr'
|
||||
1
packages/payload/src/exports/i18n/hr.ts
Normal file
1
packages/payload/src/exports/i18n/hr.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { hr } from '@payloadcms/translations/languages/hr'
|
||||
1
packages/payload/src/exports/i18n/hu.ts
Normal file
1
packages/payload/src/exports/i18n/hu.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { hu } from '@payloadcms/translations/languages/hu'
|
||||
1
packages/payload/src/exports/i18n/it.ts
Normal file
1
packages/payload/src/exports/i18n/it.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { it } from '@payloadcms/translations/languages/it'
|
||||
1
packages/payload/src/exports/i18n/ja.ts
Normal file
1
packages/payload/src/exports/i18n/ja.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { ja } from '@payloadcms/translations/languages/ja'
|
||||
1
packages/payload/src/exports/i18n/ko.ts
Normal file
1
packages/payload/src/exports/i18n/ko.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { ko } from '@payloadcms/translations/languages/ko'
|
||||
1
packages/payload/src/exports/i18n/my.ts
Normal file
1
packages/payload/src/exports/i18n/my.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { my } from '@payloadcms/translations/languages/my'
|
||||
1
packages/payload/src/exports/i18n/nb.ts
Normal file
1
packages/payload/src/exports/i18n/nb.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { nb } from '@payloadcms/translations/languages/nb'
|
||||
1
packages/payload/src/exports/i18n/nl.ts
Normal file
1
packages/payload/src/exports/i18n/nl.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { nl } from '@payloadcms/translations/languages/nl'
|
||||
1
packages/payload/src/exports/i18n/pl.ts
Normal file
1
packages/payload/src/exports/i18n/pl.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { pl } from '@payloadcms/translations/languages/pl'
|
||||
1
packages/payload/src/exports/i18n/pt.ts
Normal file
1
packages/payload/src/exports/i18n/pt.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { pt } from '@payloadcms/translations/languages/pt'
|
||||
1
packages/payload/src/exports/i18n/ro.ts
Normal file
1
packages/payload/src/exports/i18n/ro.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { ro } from '@payloadcms/translations/languages/ro'
|
||||
1
packages/payload/src/exports/i18n/rs.ts
Normal file
1
packages/payload/src/exports/i18n/rs.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { rs } from '@payloadcms/translations/languages/rs'
|
||||
1
packages/payload/src/exports/i18n/rsLatin.ts
Normal file
1
packages/payload/src/exports/i18n/rsLatin.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { rsLatin } from '@payloadcms/translations/languages/rsLatin'
|
||||
1
packages/payload/src/exports/i18n/ru.ts
Normal file
1
packages/payload/src/exports/i18n/ru.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { ru } from '@payloadcms/translations/languages/ru'
|
||||
1
packages/payload/src/exports/i18n/sv.ts
Normal file
1
packages/payload/src/exports/i18n/sv.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { sv } from '@payloadcms/translations/languages/sv'
|
||||
1
packages/payload/src/exports/i18n/th.ts
Normal file
1
packages/payload/src/exports/i18n/th.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { th } from '@payloadcms/translations/languages/th'
|
||||
1
packages/payload/src/exports/i18n/tr.ts
Normal file
1
packages/payload/src/exports/i18n/tr.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { tr } from '@payloadcms/translations/languages/tr'
|
||||
1
packages/payload/src/exports/i18n/uk.ts
Normal file
1
packages/payload/src/exports/i18n/uk.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { uk } from '@payloadcms/translations/languages/uk'
|
||||
1
packages/payload/src/exports/i18n/vi.ts
Normal file
1
packages/payload/src/exports/i18n/vi.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { vi } from '@payloadcms/translations/languages/vi'
|
||||
1
packages/payload/src/exports/i18n/zh.ts
Normal file
1
packages/payload/src/exports/i18n/zh.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { zh } from '@payloadcms/translations/languages/zh'
|
||||
1
packages/payload/src/exports/i18n/zhTw.ts
Normal file
1
packages/payload/src/exports/i18n/zhTw.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { zhTw } from '@payloadcms/translations/languages/zhTw'
|
||||
@@ -1,14 +1,13 @@
|
||||
# Payload Translations
|
||||
|
||||
These are the translations for Payload. Translations are used on both the server and the client. The admin panel uses translations to display text to the user in their selected language. The server uses translations when sending API responses.
|
||||
The home of Payloads API and Admin Panel translations.
|
||||
|
||||
## How to contribute
|
||||
|
||||
#### Updating a translation
|
||||
|
||||
1. Open the language file you wish to edit located within the `src/all` folder
|
||||
2. Update the translation value
|
||||
3. Run one of the following:
|
||||
1. Update the translation value
|
||||
2. Run one of the following:
|
||||
```sh
|
||||
yarn build
|
||||
// or
|
||||
@@ -19,9 +18,8 @@ These are the translations for Payload. Translations are used on both the server
|
||||
|
||||
#### Adding a new translation
|
||||
|
||||
1. Add the new translation key/value pair for all languages located in the `src/all` folder
|
||||
2. Open the `writeTranslationFiles.ts` file and add the key to either `clientTranslationKeys` or `serverTranslationKeys` depending on where the translation will be used.
|
||||
3. Run one of the following:
|
||||
1. Add the new translation key/value pair for **all** languages located in the `<payload-repo-root>/packages/translations/src/languages` folder
|
||||
2. Run one of the following:
|
||||
```sh
|
||||
yarn build
|
||||
// or
|
||||
@@ -32,10 +30,9 @@ These are the translations for Payload. Translations are used on both the server
|
||||
|
||||
#### Adding a new language
|
||||
|
||||
1. Create a new JSON file in the `src/all` folder with the language code as the file name (e.g. `en.json` for English)
|
||||
2. Translate all of the keys in the new file
|
||||
3. Open the `src/index.ts` file and import your json file and then export it inside the `translations` object
|
||||
4. Run one of the following:
|
||||
1. Create a new TS file in the `<payload-repo-root>/packages/translations/src/languages` folder, use the language code as the file name (e.g. `<payload-repo-root>/packages/translations/src/languages/en.ts` for English)
|
||||
2. Copy all translations from an existing language file and update all of the translations to match your new language
|
||||
3. Run one of the following:
|
||||
```sh
|
||||
yarn build
|
||||
// or
|
||||
@@ -43,6 +40,8 @@ These are the translations for Payload. Translations are used on both the server
|
||||
// or
|
||||
pnpm build
|
||||
```
|
||||
4. Import and export your new language file from within `<payload-repo-root>/packages/translations/src/exports/all.ts`
|
||||
5. Re-export the file from within `<payload-repo-root>/packages/payload/src/exports/i18n/[your-new-language].ts`
|
||||
|
||||
Here is a full list of language keys. Note that these are not all implemented, but if you would like to contribute and add a new language, you can use this list as a reference:
|
||||
|
||||
|
||||
@@ -1,480 +0,0 @@
|
||||
/* eslint-disable no-console */
|
||||
import { exec } from 'child_process'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
import { translations } from './src/all/index.js'
|
||||
import { copyFile } from './src/utilities/copyFile.js'
|
||||
import { ensureDirectoryExists } from './src/utilities/ensureDirExists.js'
|
||||
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
const dirname = path.dirname(filename)
|
||||
|
||||
const serverTranslationKeys = [
|
||||
'authentication:account',
|
||||
'authentication:api',
|
||||
'authentication:apiKey',
|
||||
'authentication:enableAPIKey',
|
||||
'authentication:newAccountCreated',
|
||||
'authentication:resetYourPassword',
|
||||
'authentication:verifyYourEmail',
|
||||
'authentication:youAreReceivingResetPassword',
|
||||
'authentication:loggedInChangePassword',
|
||||
'authentication:youDidNotRequestPassword',
|
||||
'authentication:verified',
|
||||
|
||||
'fields:textToDisplay',
|
||||
'fields:linkType',
|
||||
'fields:chooseBetweenCustomTextOrDocument',
|
||||
'fields:customURL',
|
||||
'fields:internalLink',
|
||||
'fields:enterURL',
|
||||
'fields:chooseDocumentToLink',
|
||||
'fields:openInNewTab',
|
||||
|
||||
'general:copy',
|
||||
'general:createdAt',
|
||||
'general:deletedCountSuccessfully',
|
||||
'general:deletedSuccessfully',
|
||||
'general:email',
|
||||
'general:notFound',
|
||||
'general:successfullyCreated',
|
||||
'general:successfullyDuplicated',
|
||||
'general:thisLanguage',
|
||||
'general:user',
|
||||
'general:users',
|
||||
'general:updatedAt',
|
||||
'general:updatedSuccessfully',
|
||||
'general:updatedCountSuccessfully',
|
||||
'general:value',
|
||||
'general:row',
|
||||
'general:rows',
|
||||
|
||||
'error:deletingFile',
|
||||
'error:emailOrPasswordIncorrect',
|
||||
'error:followingFieldsInvalid',
|
||||
'error:noFilesUploaded',
|
||||
'error:notAllowedToPerformAction',
|
||||
'error:problemUploadingFile',
|
||||
'error:unableToDeleteCount',
|
||||
'error:unableToUpdateCount',
|
||||
'error:unauthorized',
|
||||
'error:userLocked',
|
||||
'error:valueMustBeUnique',
|
||||
|
||||
'upload:width',
|
||||
'upload:height',
|
||||
'upload:fileSize',
|
||||
'upload:fileName',
|
||||
'upload:sizes',
|
||||
|
||||
'validation:emailAddress',
|
||||
'validation:enterNumber',
|
||||
'validation:greaterThanMax',
|
||||
'validation:invalidInput',
|
||||
'validation:invalidSelection',
|
||||
'validation:invalidSelections',
|
||||
'validation:lessThanMin',
|
||||
'validation:longerThanMin',
|
||||
'validation:notValidDate',
|
||||
'validation:required',
|
||||
'validation:requiresAtLeast',
|
||||
'validation:requiresNoMoreThan',
|
||||
'validation:requiresTwoNumbers',
|
||||
'validation:shorterThanMax',
|
||||
'validation:trueOrFalse',
|
||||
'validation:validUploadID',
|
||||
|
||||
'version:autosavedSuccessfully',
|
||||
'version:draftSavedSuccessfully',
|
||||
'version:restoredSuccessfully',
|
||||
'version:draft',
|
||||
'version:published',
|
||||
'version:status',
|
||||
]
|
||||
|
||||
const clientTranslationKeys = [
|
||||
'authentication:account',
|
||||
'authentication:accountOfCurrentUser',
|
||||
'authentication:alreadyActivated',
|
||||
'authentication:alreadyLoggedIn',
|
||||
'authentication:backToLogin',
|
||||
'authentication:beginCreateFirstUser',
|
||||
'authentication:changePassword',
|
||||
'authentication:confirmGeneration',
|
||||
'authentication:confirmPassword',
|
||||
'authentication:createFirstUser',
|
||||
'authentication:emailNotValid',
|
||||
'authentication:emailSent',
|
||||
'authentication:enableAPIKey',
|
||||
'authentication:failedToUnlock',
|
||||
'authentication:forceUnlock',
|
||||
'authentication:forgotPassword',
|
||||
'authentication:forgotPasswordEmailInstructions',
|
||||
'authentication:forgotPasswordQuestion',
|
||||
'authentication:generate',
|
||||
'authentication:generateNewAPIKey',
|
||||
'authentication:logBackIn',
|
||||
'authentication:loggedOutInactivity',
|
||||
'authentication:loggedOutSuccessfully',
|
||||
'authentication:login',
|
||||
'authentication:logOut',
|
||||
'authentication:logout',
|
||||
'authentication:logoutUser',
|
||||
'authentication:newAPIKeyGenerated',
|
||||
'authentication:newPassword',
|
||||
'authentication:resetPassword',
|
||||
'authentication:stayLoggedIn',
|
||||
'authentication:successfullyUnlocked',
|
||||
'authentication:unableToVerify',
|
||||
'authentication:verified',
|
||||
'authentication:verifiedSuccessfully',
|
||||
'authentication:verify',
|
||||
'authentication:verifyUser',
|
||||
'authentication:youAreInactive',
|
||||
|
||||
'error:autosaving',
|
||||
'error:correctInvalidFields',
|
||||
'error:deletingTitle',
|
||||
'error:loadingDocument',
|
||||
'error:noMatchedField',
|
||||
'error:notAllowedToAccessPage',
|
||||
'error:previewing',
|
||||
'error:unableToDeleteCount',
|
||||
'error:unableToUpdateCount',
|
||||
'error:unauthorized',
|
||||
'error:unknown',
|
||||
'error:unspecific',
|
||||
|
||||
'fields:addLabel',
|
||||
'fields:addLink',
|
||||
'fields:addNew',
|
||||
'fields:addNewLabel',
|
||||
'fields:addRelationship',
|
||||
'fields:addUpload',
|
||||
'fields:block',
|
||||
'fields:blocks',
|
||||
'fields:blockType',
|
||||
'fields:chooseFromExisting',
|
||||
'fields:collapseAll',
|
||||
'fields:editLink',
|
||||
'fields:editRelationship',
|
||||
'fields:itemsAndMore',
|
||||
'fields:labelRelationship',
|
||||
'fields:latitude',
|
||||
'fields:linkedTo',
|
||||
'fields:longitude',
|
||||
'fields:passwordsDoNotMatch',
|
||||
'fields:removeRelationship',
|
||||
'fields:removeUpload',
|
||||
'fields:saveChanges',
|
||||
'fields:searchForBlock',
|
||||
'fields:selectFieldsToEdit',
|
||||
'fields:showAll',
|
||||
'fields:swapRelationship',
|
||||
'fields:swapUpload',
|
||||
'fields:toggleBlock',
|
||||
'fields:uploadNewLabel',
|
||||
|
||||
'general:aboutToDeleteCount',
|
||||
'general:aboutToDelete',
|
||||
'general:addBelow',
|
||||
'general:addFilter',
|
||||
'general:adminTheme',
|
||||
'general:and',
|
||||
'general:applyChanges',
|
||||
'general:ascending',
|
||||
'general:automatic',
|
||||
'general:backToDashboard',
|
||||
'general:cancel',
|
||||
'general:changesNotSaved',
|
||||
'general:close',
|
||||
'general:collapse',
|
||||
'general:collections',
|
||||
'general:columns',
|
||||
'general:columnToSort',
|
||||
'general:confirm',
|
||||
'general:confirmDeletion',
|
||||
'general:confirmDuplication',
|
||||
'general:copied',
|
||||
'general:copy',
|
||||
'general:create',
|
||||
'general:created',
|
||||
'general:createNew',
|
||||
'general:createNewLabel',
|
||||
'general:creating',
|
||||
'general:creatingNewLabel',
|
||||
'general:dark',
|
||||
'general:dashboard',
|
||||
'general:delete',
|
||||
'general:deletedCountSuccessfully',
|
||||
'general:deleting',
|
||||
'general:descending',
|
||||
'general:deselectAllRows',
|
||||
'general:duplicate',
|
||||
'general:duplicateWithoutSaving',
|
||||
'general:edit',
|
||||
'general:editing',
|
||||
'general:editingLabel',
|
||||
'general:editLabel',
|
||||
'general:email',
|
||||
'general:emailAddress',
|
||||
'general:enterAValue',
|
||||
'general:error',
|
||||
'general:errors',
|
||||
'general:fallbackToDefaultLocale',
|
||||
'general:filters',
|
||||
'general:filterWhere',
|
||||
'general:globals',
|
||||
'general:language',
|
||||
'general:lastModified',
|
||||
'general:leaveAnyway',
|
||||
'general:leaveWithoutSaving',
|
||||
'general:light',
|
||||
'general:livePreview',
|
||||
'general:loading',
|
||||
'general:locale',
|
||||
'general:menu',
|
||||
'general:moveDown',
|
||||
'general:moveUp',
|
||||
'general:noFiltersSet',
|
||||
'general:noLabel',
|
||||
'general:none',
|
||||
'general:noOptions',
|
||||
'general:noResults',
|
||||
'general:notFound',
|
||||
'general:nothingFound',
|
||||
'general:noValue',
|
||||
'general:of',
|
||||
'general:open',
|
||||
'general:or',
|
||||
'general:order',
|
||||
'general:pageNotFound',
|
||||
'general:password',
|
||||
'general:payloadSettings',
|
||||
'general:perPage',
|
||||
'general:remove',
|
||||
'general:reset',
|
||||
'general:row',
|
||||
'general:rows',
|
||||
'general:save',
|
||||
'general:saving',
|
||||
'general:searchBy',
|
||||
'general:selectAll',
|
||||
'general:selectAllRows',
|
||||
'general:selectedCount',
|
||||
'general:selectValue',
|
||||
'general:showAllLabel',
|
||||
'general:sorryNotFound',
|
||||
'general:sort',
|
||||
'general:sortByLabelDirection',
|
||||
'general:stayOnThisPage',
|
||||
'general:submissionSuccessful',
|
||||
'general:submit',
|
||||
'general:successfullyCreated',
|
||||
'general:successfullyDeleted',
|
||||
'general:thisLanguage',
|
||||
'general:titleDeleted',
|
||||
'general:unauthorized',
|
||||
'general:unsavedChangesDuplicate',
|
||||
'general:untitled',
|
||||
'general:updatedAt',
|
||||
'general:updatedCountSuccessfully',
|
||||
'general:updatedSuccessfully',
|
||||
'general:updating',
|
||||
'general:welcome',
|
||||
|
||||
'operators:equals',
|
||||
'operators:exists',
|
||||
'operators:isNotIn',
|
||||
'operators:isIn',
|
||||
'operators:contains',
|
||||
'operators:isLike',
|
||||
'operators:isNotEqualTo',
|
||||
'operators:near',
|
||||
'operators:isGreaterThan',
|
||||
'operators:isLessThan',
|
||||
'operators:isGreaterThanOrEqualTo',
|
||||
'operators:isLessThanOrEqualTo',
|
||||
|
||||
'upload:crop',
|
||||
'upload:cropToolDescription',
|
||||
'upload:dragAndDrop',
|
||||
'upload:editImage',
|
||||
'upload:focalPoint',
|
||||
'upload:focalPointDescription',
|
||||
'upload:height',
|
||||
'upload:previewSizes',
|
||||
'upload:selectCollectionToBrowse',
|
||||
'upload:selectFile',
|
||||
'upload:setCropArea',
|
||||
'upload:setFocalPoint',
|
||||
'upload:sizesFor',
|
||||
'upload:width',
|
||||
|
||||
'validation:fieldHasNo',
|
||||
'validation:limitReached',
|
||||
'validation:required',
|
||||
'validation:requiresAtLeast',
|
||||
|
||||
'version:aboutToPublishSelection',
|
||||
'version:aboutToRestore',
|
||||
'version:aboutToRestoreGlobal',
|
||||
'version:aboutToRevertToPublished',
|
||||
'version:aboutToUnpublish',
|
||||
'version:aboutToUnpublishSelection',
|
||||
'version:autosave',
|
||||
'version:autosavedSuccessfully',
|
||||
'version:changed',
|
||||
'version:confirmRevertToSaved',
|
||||
'version:compareVersion',
|
||||
'version:confirmPublish',
|
||||
'version:confirmUnpublish',
|
||||
'version:confirmVersionRestoration',
|
||||
'version:draft',
|
||||
'version:draftSavedSuccessfully',
|
||||
'version:lastSavedAgo',
|
||||
'version:noFurtherVersionsFound',
|
||||
'version:noRowsFound',
|
||||
'version:preview',
|
||||
'version:problemRestoringVersion',
|
||||
'version:publish',
|
||||
'version:publishChanges',
|
||||
'version:published',
|
||||
'version:publishing',
|
||||
'version:restoredSuccessfully',
|
||||
'version:restoreThisVersion',
|
||||
'version:restoring',
|
||||
'version:revertToPublished',
|
||||
'version:saveDraft',
|
||||
'version:selectLocales',
|
||||
'version:selectVersionToCompare',
|
||||
'version:showLocales',
|
||||
'version:status',
|
||||
'version:type',
|
||||
'version:unpublish',
|
||||
'version:unpublishing',
|
||||
'version:versionCreatedOn',
|
||||
'version:versionID',
|
||||
'version:version',
|
||||
'version:versions',
|
||||
'version:viewingVersion',
|
||||
'version:viewingVersionGlobal',
|
||||
'version:viewingVersions',
|
||||
'version:viewingVersionsGlobal',
|
||||
]
|
||||
|
||||
const DESTINATION_ROOT = './src/_generatedFiles_'
|
||||
const SOURCE_DIR = './src/all'
|
||||
|
||||
function filterKeys(obj, parentGroupKey = '', keys) {
|
||||
const result = {}
|
||||
|
||||
for (const [namespaceKey, value] of Object.entries(obj)) {
|
||||
// Skip $schema key
|
||||
if (namespaceKey === '$schema') {
|
||||
result[namespaceKey] = value
|
||||
continue
|
||||
}
|
||||
|
||||
if (typeof value === 'object') {
|
||||
const filteredObject = filterKeys(value, namespaceKey, keys)
|
||||
if (Object.keys(filteredObject).length > 0) {
|
||||
result[namespaceKey] = filteredObject
|
||||
}
|
||||
} else {
|
||||
for (const key of keys) {
|
||||
const [groupKey, selector] = key.split(':')
|
||||
|
||||
if (parentGroupKey === groupKey) {
|
||||
if (namespaceKey === selector) {
|
||||
result[selector] = value
|
||||
} else {
|
||||
const pluralKeys = ['zero', 'one', 'two', 'few', 'many', 'other']
|
||||
pluralKeys.forEach((pluralKey) => {
|
||||
if (namespaceKey === `${selector}_${pluralKey}`) {
|
||||
result[`${selector}_${pluralKey}`] = value
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function sortObject(obj) {
|
||||
const sortedObject = {}
|
||||
Object.keys(obj)
|
||||
.sort()
|
||||
.forEach((key) => {
|
||||
if (typeof obj[key] === 'object') {
|
||||
sortedObject[key] = sortObject(obj[key])
|
||||
} else {
|
||||
sortedObject[key] = obj[key]
|
||||
}
|
||||
})
|
||||
return sortedObject
|
||||
}
|
||||
|
||||
function build() {
|
||||
return new Promise((resolve, reject) => {
|
||||
ensureDirectoryExists(path.resolve(dirname, `${DESTINATION_ROOT}/client`))
|
||||
ensureDirectoryExists(path.resolve(dirname, `${DESTINATION_ROOT}/api`))
|
||||
|
||||
try {
|
||||
// build up the client and server translation files
|
||||
for (const [locale, values] of Object.entries(translations)) {
|
||||
const dest1 = path.resolve(dirname, `${DESTINATION_ROOT}/client/${locale}.js`)
|
||||
|
||||
const clientTranslations = sortObject(filterKeys(values, '', clientTranslationKeys))
|
||||
|
||||
fs.writeFileSync(dest1, 'export default ' + JSON.stringify(clientTranslations, null, 2), {
|
||||
flag: 'w+',
|
||||
})
|
||||
|
||||
const serverTranslations = sortObject(filterKeys(values, '', serverTranslationKeys))
|
||||
const dest2 = path.resolve(dirname, `${DESTINATION_ROOT}/api/${locale}.js`)
|
||||
|
||||
fs.writeFileSync(dest2, 'export default ' + JSON.stringify(serverTranslations, null, 2), {
|
||||
flag: 'w+',
|
||||
})
|
||||
|
||||
console.info('Rebuilt:', filename)
|
||||
}
|
||||
|
||||
// Copy barrel file to both client and api folders
|
||||
copyFile(
|
||||
path.resolve(dirname, `${SOURCE_DIR}/index.ts`),
|
||||
path.resolve(dirname, `${DESTINATION_ROOT}/api/index.ts`),
|
||||
)
|
||||
copyFile(
|
||||
path.resolve(dirname, `${SOURCE_DIR}/index.ts`),
|
||||
path.resolve(dirname, `${DESTINATION_ROOT}/client/index.ts`),
|
||||
)
|
||||
|
||||
// Run prettier from CLI so that files pass the pre-commit hook:
|
||||
console.info('Running prettier...')
|
||||
exec('prettier --write "**/*.js"', (err, stdout) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
} else {
|
||||
console.info(stdout)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
build()
|
||||
.then(() => {
|
||||
console.log('Built client and api translation files.')
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error occurred:', error)
|
||||
})
|
||||
@@ -62,7 +62,7 @@ export const _ArrayField: React.FC<ArrayFieldProps> = (props) => {
|
||||
labelProps,
|
||||
localized,
|
||||
maxRows,
|
||||
minRows,
|
||||
minRows: minRowsProp,
|
||||
path: pathFromProps,
|
||||
permissions,
|
||||
readOnly: readOnlyFromProps,
|
||||
@@ -72,6 +72,7 @@ export const _ArrayField: React.FC<ArrayFieldProps> = (props) => {
|
||||
|
||||
const { indexPath, readOnly: readOnlyFromContext } = useFieldProps()
|
||||
const readOnly = readOnlyFromProps || readOnlyFromContext
|
||||
const minRows = minRowsProp ?? required ? 1 : 0
|
||||
|
||||
const { setDocFieldPreferences } = useDocumentInfo()
|
||||
const { addFieldRow, dispatchFields, setModified } = useForm()
|
||||
@@ -300,7 +301,7 @@ export const _ArrayField: React.FC<ArrayFieldProps> = (props) => {
|
||||
{t('validation:requiresAtLeast', {
|
||||
count: minRows,
|
||||
label:
|
||||
getTranslation(minRows ? labels.plural : labels.singular, i18n) ||
|
||||
getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) ||
|
||||
t(minRows > 1 ? 'general:row' : 'general:rows'),
|
||||
})}
|
||||
</Banner>
|
||||
|
||||
@@ -67,7 +67,7 @@ const _BlocksField: React.FC<BlocksFieldProps> = (props) => {
|
||||
labels: labelsFromProps,
|
||||
localized,
|
||||
maxRows,
|
||||
minRows,
|
||||
minRows: minRowsProp,
|
||||
path: pathFromProps,
|
||||
readOnly: readOnlyFromProps,
|
||||
required,
|
||||
@@ -76,6 +76,7 @@ const _BlocksField: React.FC<BlocksFieldProps> = (props) => {
|
||||
|
||||
const { indexPath, readOnly: readOnlyFromContext } = useFieldProps()
|
||||
const readOnly = readOnlyFromProps || readOnlyFromContext
|
||||
const minRows = minRowsProp ?? required ? 1 : 0
|
||||
|
||||
const { setDocFieldPreferences } = useDocumentInfo()
|
||||
const { addFieldRow, dispatchFields, setModified } = useForm()
|
||||
@@ -313,12 +314,9 @@ const _BlocksField: React.FC<BlocksFieldProps> = (props) => {
|
||||
<Banner type="error">
|
||||
{t('validation:requiresAtLeast', {
|
||||
count: minRows,
|
||||
label: getTranslation(
|
||||
minRows === 1 || typeof minRows === 'undefined'
|
||||
? labels.singular
|
||||
: labels.plural,
|
||||
i18n,
|
||||
),
|
||||
label:
|
||||
getTranslation(minRows > 1 ? labels.plural : labels.singular, i18n) ||
|
||||
t(minRows > 1 ? 'general:row' : 'general:rows'),
|
||||
})}
|
||||
</Banner>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user