From 186b97ebbb2331c7c7e5825826c0f6d8ec23b0ff Mon Sep 17 00:00:00 2001 From: Harley Alexander Date: Mon, 23 Mar 2020 16:39:30 +1100 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=8F=B7=20convert=20ra-language-englis?= =?UTF-8?q?h=20and=20ra-language-french=20to=20typescript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ra-core/src/i18n/TranslationMessages.ts | 143 ++++++++++++++++++ packages/ra-core/src/i18n/index.ts | 1 + packages/ra-i18n-polyglot/src/index.ts | 6 +- packages/ra-language-english/package.json | 19 ++- .../{index.js => src/index.ts} | 6 +- packages/ra-language-english/tsconfig.json | 11 ++ packages/ra-language-french/package.json | 13 +- .../{index.js => src/index.ts} | 6 +- packages/ra-language-french/tsconfig.json | 11 ++ 9 files changed, 209 insertions(+), 7 deletions(-) create mode 100644 packages/ra-core/src/i18n/TranslationMessages.ts rename packages/ra-language-english/{index.js => src/index.ts} (97%) create mode 100644 packages/ra-language-english/tsconfig.json rename packages/ra-language-french/{index.js => src/index.ts} (97%) create mode 100644 packages/ra-language-french/tsconfig.json diff --git a/packages/ra-core/src/i18n/TranslationMessages.ts b/packages/ra-core/src/i18n/TranslationMessages.ts new file mode 100644 index 00000000000..04517cce493 --- /dev/null +++ b/packages/ra-core/src/i18n/TranslationMessages.ts @@ -0,0 +1,143 @@ +interface StringMap { + [key: string]: StringMap | string; +} + +export interface TranslationMessages { + // for custom translation strings + [key: string]: StringMap | string; + ra?: { + action?: { + // for custom translation strings + [key: string]: StringMap | string; + add_filter?: string; + add?: string; + back?: string; + bulk_actions?: string; + cancel?: string; + clear_input_value?: string; + clone?: string; + confirm?: string; + create?: string; + delete?: string; + edit?: string; + export?: string; + list?: string; + refresh?: string; + remove_filter?: string; + remove?: string; + save?: string; + search?: string; + show?: string; + sort?: string; + undo?: string; + expand?: string; + close?: string; + }; + boolean?: { + [key: string]: StringMap | string; + true?: string; + false?: string; + null?: string; + }; + page?: { + [key: string]: StringMap | string; + create?: string; + dashboard?: string; + edit?: string; + error?: string; + list?: string; + loading?: string; + not_found?: string; + show?: string; + empty?: string; + invite?: string; + }; + input?: { + [key: string]: StringMap | string; + file?: { + [key: string]: StringMap | string; + upload_several?: string; + upload_single?: string; + }; + image: { + [key: string]: StringMap | string; + upload_several?: string; + upload_single?: string; + }; + references: { + [key: string]: StringMap | string; + all_missing?: string; + many_missing?: string; + single_missing?: string; + }; + password: { + [key: string]: StringMap | string; + toggle_visible?: string; + toggle_hidden?: string; + }; + }; + message: { + [key: string]: StringMap | string; + about?: string; + are_you_sure?: string; + bulk_delete_content?: string; + bulk_delete_title?: string; + delete_content?: string; + delete_title?: string; + details?: string; + error?: string; + invalid_form?: string; + loading?: string; + no?: string; + not_found?: string; + yes?: string; + }; + navigation: { + [key: string]: StringMap | string; + no_results?: string; + no_more_results?: string; + page_out_of_boundaries?: string; + page_out_from_end?: string; + page_out_from_begin?: string; + page_range_info?: string; + page_rows_per_page?: string; + next?: string; + prev?: string; + }; + auth: { + [key: string]: StringMap | string; + auth_check_error?: string; + user_menu?: string; + username?: string; + password?: string; + sign_in?: string; + sign_in_error?: string; + logout?: string; + }; + notification: { + [key: string]: StringMap | string; + updated?: string; + created?: string; + deleted?: string; + bad_item?: string; + item_doesnt_exist?: string; + http_error?: string; + data_provider_error?: string; + i18n_error?: string; + canceled?: string; + logged_out?: string; + }; + validation: { + [key: string]: StringMap | string; + required?: string; + minLength?: string; + maxLength?: string; + minValue?: string; + maxValue?: string; + number?: string; + email?: string; + oneOf?: string; + regex?: string; + }; + }; +} diff --git a/packages/ra-core/src/i18n/index.ts b/packages/ra-core/src/i18n/index.ts index 3c7d112ea92..9782fedf160 100644 --- a/packages/ra-core/src/i18n/index.ts +++ b/packages/ra-core/src/i18n/index.ts @@ -23,3 +23,4 @@ export const DEFAULT_LOCALE = 'en'; export * from './TranslationUtils'; export * from './TranslationContext'; +export * from './TranslationMessages'; diff --git a/packages/ra-i18n-polyglot/src/index.ts b/packages/ra-i18n-polyglot/src/index.ts index 336cc860d2c..11011ff6aae 100644 --- a/packages/ra-i18n-polyglot/src/index.ts +++ b/packages/ra-i18n-polyglot/src/index.ts @@ -1,8 +1,8 @@ import Polyglot from 'node-polyglot'; -import { I18nProvider } from 'ra-core'; +import { I18nProvider, TranslationMessages } from 'ra-core'; -type GetMessages = (locale: string) => Object; +type GetMessages = (locale: string) => TranslationMessages; /** * Build a polyglot-based i18nProvider based on a function returning the messages for a locale @@ -45,7 +45,7 @@ export default ( // so we systematically return a Promise for the messages // i18nProvider may return a Promise for language changes, resolve(getMessages(newLocale as string)) - ).then((messages: Object) => { + ).then((messages: TranslationMessages) => { locale = newLocale; const newPolyglot = new Polyglot({ locale: newLocale, diff --git a/packages/ra-language-english/package.json b/packages/ra-language-english/package.json index 60b692d5f41..7c498f14feb 100644 --- a/packages/ra-language-english/package.json +++ b/packages/ra-language-english/package.json @@ -2,11 +2,28 @@ "name": "ra-language-english", "version": "3.2.0", "description": "English messages for react-admin, the frontend framework for building admin applications on top of REST/GraphQL services", - "main": "index.js", "repository": { "type": "git", "url": "git+https://github.com/marmelab/react-admin.git" }, + "files": [ + "*.md", + "lib", + "esm", + "src" + ], + "main": "lib/index.js", + "module": "esm/index.js", + "types": "esm/index.d.ts", + "scripts": { + "build": "yarn run build-cjs && yarn run build-esm", + "build-cjs": "rimraf ./lib && tsc", + "build-esm": "rimraf ./esm && tsc --outDir esm --module es2015", + "watch": "tsc --outDir esm --module es2015 --watch" + }, + "dependencies": { + "ra-core": "^3.3.2" + }, "keywords": [ "react", "react-admin", diff --git a/packages/ra-language-english/index.js b/packages/ra-language-english/src/index.ts similarity index 97% rename from packages/ra-language-english/index.js rename to packages/ra-language-english/src/index.ts index 7c4981b344c..c7bdcbaf68c 100644 --- a/packages/ra-language-english/index.js +++ b/packages/ra-language-english/src/index.ts @@ -1,4 +1,6 @@ -module.exports = { +import { TranslationMessages } from 'ra-core'; + +const englishMessages: TranslationMessages = { ra: { action: { add_filter: 'Add filter', @@ -133,3 +135,5 @@ module.exports = { }, }, }; + +export default englishMessages; diff --git a/packages/ra-language-english/tsconfig.json b/packages/ra-language-english/tsconfig.json new file mode 100644 index 00000000000..e8a21555108 --- /dev/null +++ b/packages/ra-language-english/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "lib", + "rootDir": "src", + "declaration": true, + "allowJs": false + }, + "exclude": ["**/*.spec.ts", "**/*.spec.tsx", "**/*.spec.js"], + "include": ["src"] +} diff --git a/packages/ra-language-french/package.json b/packages/ra-language-french/package.json index e83a235dfbc..fce9a7bb4da 100644 --- a/packages/ra-language-french/package.json +++ b/packages/ra-language-french/package.json @@ -2,11 +2,22 @@ "name": "ra-language-french", "version": "3.2.0", "description": "French messages for react-admin, the frontend framework for building admin applications on top of REST/GraphQL services", - "main": "index.js", "repository": { "type": "git", "url": "git+https://github.com/marmelab/react-admin.git" }, + "main": "lib/index.js", + "module": "esm/index.js", + "types": "esm/index.d.ts", + "scripts": { + "build": "yarn run build-cjs && yarn run build-esm", + "build-cjs": "rimraf ./lib && tsc", + "build-esm": "rimraf ./esm && tsc --outDir esm --module es2015", + "watch": "tsc --outDir esm --module es2015 --watch" + }, + "dependencies": { + "ra-core": "^3.3.2" + }, "keywords": [ "react", "react-admin", diff --git a/packages/ra-language-french/index.js b/packages/ra-language-french/src/index.ts similarity index 97% rename from packages/ra-language-french/index.js rename to packages/ra-language-french/src/index.ts index c6546e79155..52160a069f3 100644 --- a/packages/ra-language-french/index.js +++ b/packages/ra-language-french/src/index.ts @@ -1,4 +1,6 @@ -module.exports = { +import { TranslationMessages } from 'ra-core'; + +const frenchMessages: TranslationMessages = { ra: { action: { add_filter: 'Ajouter un filtre', @@ -138,3 +140,5 @@ module.exports = { }, }, }; + +export default frenchMessages; diff --git a/packages/ra-language-french/tsconfig.json b/packages/ra-language-french/tsconfig.json new file mode 100644 index 00000000000..e8a21555108 --- /dev/null +++ b/packages/ra-language-french/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "lib", + "rootDir": "src", + "declaration": true, + "allowJs": false + }, + "exclude": ["**/*.spec.ts", "**/*.spec.tsx", "**/*.spec.js"], + "include": ["src"] +} From 11ded5d0575681c48966b0e1d5c0e80cec4f96d4 Mon Sep 17 00:00:00 2001 From: Harley Alexander Date: Mon, 23 Mar 2020 17:37:34 +1100 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=8F=B7=20Ensure=20demo=20builds=20cor?= =?UTF-8?q?rectly,=20improved=20TranslationMessages=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/demo/src/i18n/{en.js => en.ts} | 5 ++++- examples/demo/src/i18n/{fr.js => fr.ts} | 5 ++++- packages/ra-core/src/i18n/TranslationMessages.ts | 6 ++---- packages/ra-i18n-polyglot/src/index.ts | 4 +++- 4 files changed, 13 insertions(+), 7 deletions(-) rename examples/demo/src/i18n/{en.js => en.ts} (97%) rename examples/demo/src/i18n/{fr.js => fr.ts} (97%) diff --git a/examples/demo/src/i18n/en.js b/examples/demo/src/i18n/en.ts similarity index 97% rename from examples/demo/src/i18n/en.js rename to examples/demo/src/i18n/en.ts index 261809eca29..6a499ad07b3 100644 --- a/examples/demo/src/i18n/en.js +++ b/examples/demo/src/i18n/en.ts @@ -1,6 +1,7 @@ +import { TranslationMessages } from 'ra-core'; import englishMessages from 'ra-language-english'; -export default { +const customEnglishMessages: TranslationMessages = { ...englishMessages, pos: { search: 'Search', @@ -172,3 +173,5 @@ export default { }, }, }; + +export default customEnglishMessages; diff --git a/examples/demo/src/i18n/fr.js b/examples/demo/src/i18n/fr.ts similarity index 97% rename from examples/demo/src/i18n/fr.js rename to examples/demo/src/i18n/fr.ts index 6602d0efa13..db7a8fe110b 100644 --- a/examples/demo/src/i18n/fr.js +++ b/examples/demo/src/i18n/fr.ts @@ -1,6 +1,7 @@ +import { TranslationMessages } from 'ra-core'; import frenchMessages from 'ra-language-french'; -export default { +const customFrenchMessages: TranslationMessages = { ...frenchMessages, pos: { search: 'Rechercher', @@ -188,3 +189,5 @@ export default { }, }, }; + +export default customFrenchMessages; diff --git a/packages/ra-core/src/i18n/TranslationMessages.ts b/packages/ra-core/src/i18n/TranslationMessages.ts index 04517cce493..f5699f2e40a 100644 --- a/packages/ra-core/src/i18n/TranslationMessages.ts +++ b/packages/ra-core/src/i18n/TranslationMessages.ts @@ -1,10 +1,8 @@ interface StringMap { - [key: string]: StringMap | string; + [key: string]: StringMap | string | undefined; } -export interface TranslationMessages { - // for custom translation strings - [key: string]: StringMap | string; +export interface TranslationMessages extends StringMap { ra?: { action?: { // for custom translation strings diff --git a/packages/ra-i18n-polyglot/src/index.ts b/packages/ra-i18n-polyglot/src/index.ts index 11011ff6aae..f5795a908bc 100644 --- a/packages/ra-i18n-polyglot/src/index.ts +++ b/packages/ra-i18n-polyglot/src/index.ts @@ -2,7 +2,9 @@ import Polyglot from 'node-polyglot'; import { I18nProvider, TranslationMessages } from 'ra-core'; -type GetMessages = (locale: string) => TranslationMessages; +type GetMessages = ( + locale: string +) => TranslationMessages | Promise; /** * Build a polyglot-based i18nProvider based on a function returning the messages for a locale From 1fe33e43e5be5301a8b9c48067a179170ddd5c0e Mon Sep 17 00:00:00 2001 From: Harley Alexander Date: Mon, 23 Mar 2020 17:49:17 +1100 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=92=9A=20Include=20language=20package?= =?UTF-8?q?s=20in=20makefile=20to=20let=20Travis=20CI=20pass.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ee5dbf8eb00..e8c04c5b0da 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,14 @@ build-ra-ui-materialui: @echo "Transpiling ra-ui-materialui files..."; @cd ./packages/ra-ui-materialui && yarn -s build +build-ra-language-english: + @echo "Transpiling ra-language-english files..."; + @cd ./packages/ra-language-english && yarn -s build + +build-ra-language-french: + @echo "Transpiling ra-language-french files..."; + @cd ./packages/ra-language-french && yarn -s build + build-react-admin: @echo "Transpiling react-admin files..."; @rm -rf ./packages/react-admin/docs @@ -80,7 +88,7 @@ build-data-generator: @echo "Transpiling data-generator files..."; @cd ./examples/data-generator && yarn -s build -build: build-ra-core build-ra-ui-materialui build-ra-data-fakerest build-ra-data-json-server build-ra-data-simple-rest build-ra-data-graphql build-ra-data-graphcool build-ra-data-graphql-simple build-ra-i18n-polyglot build-ra-input-rich-text build-data-generator build-react-admin ## compile ES6 files to JS +build: build-ra-core build-ra-ui-materialui build-ra-data-fakerest build-ra-data-json-server build-ra-data-simple-rest build-ra-data-graphql build-ra-data-graphcool build-ra-data-graphql-simple build-ra-i18n-polyglot build-ra-input-rich-text build-data-generator build-ra-language-english build-ra-language-french build-react-admin ## compile ES6 files to JS doc: ## compile doc as html and launch doc web server @yarn -s doc From a107b8f9092793392de3d5d9236bf82c6cae84ff Mon Sep 17 00:00:00 2001 From: Harley Alexander Date: Tue, 24 Mar 2020 08:47:21 +1100 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=91=8C=20remove=20optional=20paramete?= =?UTF-8?q?rs=20in=20translations=20per=20review=20request?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ra-core/src/i18n/TranslationMessages.ts | 198 +++++++++--------- 1 file changed, 99 insertions(+), 99 deletions(-) diff --git a/packages/ra-core/src/i18n/TranslationMessages.ts b/packages/ra-core/src/i18n/TranslationMessages.ts index f5699f2e40a..0840964a9e8 100644 --- a/packages/ra-core/src/i18n/TranslationMessages.ts +++ b/packages/ra-core/src/i18n/TranslationMessages.ts @@ -3,139 +3,139 @@ interface StringMap { } export interface TranslationMessages extends StringMap { - ra?: { - action?: { + ra: { + action: { // for custom translation strings [key: string]: StringMap | string; - add_filter?: string; - add?: string; - back?: string; - bulk_actions?: string; - cancel?: string; - clear_input_value?: string; - clone?: string; - confirm?: string; - create?: string; - delete?: string; - edit?: string; - export?: string; - list?: string; - refresh?: string; - remove_filter?: string; - remove?: string; - save?: string; - search?: string; - show?: string; - sort?: string; - undo?: string; - expand?: string; - close?: string; + add_filter: string; + add: string; + back: string; + bulk_actions: string; + cancel: string; + clear_input_value: string; + clone: string; + confirm: string; + create: string; + delete: string; + edit: string; + export: string; + list: string; + refresh: string; + remove_filter: string; + remove: string; + save: string; + search: string; + show: string; + sort: string; + undo: string; + expand: string; + close: string; }; - boolean?: { + boolean: { [key: string]: StringMap | string; - true?: string; - false?: string; - null?: string; + true: string; + false: string; + null: string; }; - page?: { + page: { [key: string]: StringMap | string; - create?: string; - dashboard?: string; - edit?: string; - error?: string; - list?: string; - loading?: string; - not_found?: string; - show?: string; - empty?: string; - invite?: string; + create: string; + dashboard: string; + edit: string; + error: string; + list: string; + loading: string; + not_found: string; + show: string; + empty: string; + invite: string; }; - input?: { + input: { [key: string]: StringMap | string; - file?: { + file: { [key: string]: StringMap | string; - upload_several?: string; - upload_single?: string; + upload_several: string; + upload_single: string; }; image: { [key: string]: StringMap | string; - upload_several?: string; - upload_single?: string; + upload_several: string; + upload_single: string; }; references: { [key: string]: StringMap | string; - all_missing?: string; - many_missing?: string; - single_missing?: string; + all_missing: string; + many_missing: string; + single_missing: string; }; password: { [key: string]: StringMap | string; - toggle_visible?: string; - toggle_hidden?: string; + toggle_visible: string; + toggle_hidden: string; }; }; message: { [key: string]: StringMap | string; - about?: string; - are_you_sure?: string; - bulk_delete_content?: string; - bulk_delete_title?: string; - delete_content?: string; - delete_title?: string; - details?: string; - error?: string; - invalid_form?: string; - loading?: string; - no?: string; - not_found?: string; - yes?: string; + about: string; + are_you_sure: string; + bulk_delete_content: string; + bulk_delete_title: string; + delete_content: string; + delete_title: string; + details: string; + error: string; + invalid_form: string; + loading: string; + no: string; + not_found: string; + yes: string; }; navigation: { [key: string]: StringMap | string; - no_results?: string; - no_more_results?: string; - page_out_of_boundaries?: string; - page_out_from_end?: string; - page_out_from_begin?: string; - page_range_info?: string; - page_rows_per_page?: string; - next?: string; - prev?: string; + no_results: string; + no_more_results: string; + page_out_of_boundaries: string; + page_out_from_end: string; + page_out_from_begin: string; + page_range_info: string; + page_rows_per_page: string; + next: string; + prev: string; }; auth: { [key: string]: StringMap | string; - auth_check_error?: string; - user_menu?: string; - username?: string; - password?: string; - sign_in?: string; - sign_in_error?: string; - logout?: string; + auth_check_error: string; + user_menu: string; + username: string; + password: string; + sign_in: string; + sign_in_error: string; + logout: string; }; notification: { [key: string]: StringMap | string; - updated?: string; - created?: string; - deleted?: string; - bad_item?: string; - item_doesnt_exist?: string; - http_error?: string; - data_provider_error?: string; - i18n_error?: string; - canceled?: string; - logged_out?: string; + updated: string; + created: string; + deleted: string; + bad_item: string; + item_doesnt_exist: string; + http_error: string; + data_provider_error: string; + i18n_error: string; + canceled: string; + logged_out: string; }; validation: { [key: string]: StringMap | string; - required?: string; - minLength?: string; - maxLength?: string; - minValue?: string; - maxValue?: string; - number?: string; - email?: string; - oneOf?: string; - regex?: string; + required: string; + minLength: string; + maxLength: string; + minValue: string; + maxValue: string; + number: string; + email: string; + oneOf: string; + regex: string; }; }; }