From f8e7716f917eef2c685b9519590fa13243edc503 Mon Sep 17 00:00:00 2001 From: qingyan Date: Sun, 28 Apr 2024 15:37:38 +0800 Subject: [PATCH 1/5] feat(i18n): add locale de-DE & ms-MY & ar-SA & vi-VN --- docs/guide/i18n.en.md | 6 + docs/guide/i18n.zh.md | 6 + .../tests/config-provider.test.tsx | 36 +++-- src/locales/ar-SA.ts | 112 ++++++++++++++++ src/locales/de-DE.ts | 125 ++++++++++++++++++ src/locales/ms-MY.ts | 118 +++++++++++++++++ src/locales/vi-VN.ts | 112 ++++++++++++++++ 7 files changed, 502 insertions(+), 13 deletions(-) create mode 100644 src/locales/ar-SA.ts create mode 100644 src/locales/de-DE.ts create mode 100644 src/locales/ms-MY.ts create mode 100644 src/locales/vi-VN.ts diff --git a/docs/guide/i18n.en.md b/docs/guide/i18n.en.md index 73cdf595ea..f6b96d0f9a 100644 --- a/docs/guide/i18n.en.md +++ b/docs/guide/i18n.en.md @@ -37,6 +37,12 @@ The following languages are currently supported: | Russian (Russia) | ru-RU | | Turkish (Türkçe) | tr-TR | | Thai | th-TH | +| French | fr-FR | +| German | de-DE | +| Malay | ms-MY | +| Arabic | ar-SA | +| Portuguese | pt-BR | +| Vietnamese | vi-VN | See more usage at [ConfigProvider](../components/config-provider). diff --git a/docs/guide/i18n.zh.md b/docs/guide/i18n.zh.md index 5422359e90..491fd8607b 100644 --- a/docs/guide/i18n.zh.md +++ b/docs/guide/i18n.zh.md @@ -36,6 +36,12 @@ return ( | 俄罗斯语 | ru-RU | | 土耳其语 | tr-TR | | 泰语 | th-TH | +| 法语 | fr-FR | +| 德语 | de-DE | +| 马来语 | ms-MY | +| 阿拉伯语 | ar-SA | +| 葡萄牙语 | pt-BR | +| 越南语 | vi-VN | 具体的使用方法请参考 [ConfigProvider](../components/config-provider) 文档。 diff --git a/src/components/config-provider/tests/config-provider.test.tsx b/src/components/config-provider/tests/config-provider.test.tsx index 8b348b6bc3..b8919863db 100644 --- a/src/components/config-provider/tests/config-provider.test.tsx +++ b/src/components/config-provider/tests/config-provider.test.tsx @@ -1,36 +1,41 @@ +import MockDate from 'mockdate' import React from 'react' import { render } from 'testing' -import MockDate from 'mockdate' import ConfigProvider from '..' +import { useConfig } from '../' import Calendar from '../../calendar' import CalendarPickerView from '../../calendar-picker-view' import Cascader from '../../cascader' import ErrorBlock from '../../error-block' import Form from '../../form' +import ImageUploader from '../../image-uploader' import Picker from '../../picker' import SearchBar from '../../search-bar' -import ImageUploader from '../../image-uploader' -import { useConfig } from '../' -import zhCN from '../../../locales/zh-CN' -import zhTW from '../../../locales/zh-TW' -import zhHK from '../../../locales/zh-HK' +import arSA from '../../../locales/ar-SA' +import daDK from '../../../locales/da-DK' +import deDE from '../../../locales/de-DE' import enUS from '../../../locales/en-US' -import faIR from '../../../locales/fa-IR' import esES from '../../../locales/es-ES' -import koKR from '../../../locales/ko-KR' -import jaJP from '../../../locales/ja-JP' +import faIR from '../../../locales/fa-IR' import frFR from '../../../locales/fr-FR' +import huHU from '../../../locales/hu-HU' import idID from '../../../locales/id-ID' -import kkKZ from '../../../locales/kk-KZ' import itIT from '../../../locales/it-IT' -import daDK from '../../../locales/da-DK' +import jaJP from '../../../locales/ja-JP' +import kkKZ from '../../../locales/kk-KZ' +import koKR from '../../../locales/ko-KR' +import msMY from '../../../locales/ms-MY' import nbNO from '../../../locales/nb-NO' import nlNL from '../../../locales/nl-NL' +import ptBR from '../../../locales/pt-BR' import ruRU from '../../../locales/ru-RU' -import trTR from '../../../locales/tr-TR' import thTH from '../../../locales/th-TH' -import huHU from '../../../locales/hu-HU' +import trTR from '../../../locales/tr-TR' +import viVN from '../../../locales/vi-VN' +import zhCN from '../../../locales/zh-CN' +import zhHK from '../../../locales/zh-HK' +import zhTW from '../../../locales/zh-TW' const locales = [ zhCN, @@ -52,6 +57,11 @@ const locales = [ ruRU, trTR, thTH, + deDE, + msMY, + arSA, + ptBR, + viVN, ] describe('ConfigProvider', () => { diff --git a/src/locales/ar-SA.ts b/src/locales/ar-SA.ts new file mode 100644 index 0000000000..b648972051 --- /dev/null +++ b/src/locales/ar-SA.ts @@ -0,0 +1,112 @@ +import { mergeLocale } from '../utils/merge-locale' +import { base } from './base' + +const typeTemplate = '${label} غير صالح ${type}' + +const arSA = mergeLocale(base, { + 'locale': 'ar-SA', + 'common': { + 'confirm': 'نعم', + 'cancel': 'إلغاء', + 'loading': 'جار التحميل', + 'close': 'إغلاق', + }, + 'Calendar': { + 'title': 'اختيار التاريخ', + 'confirm': 'تأكيد', + 'start': 'يبدأ', + 'end': 'ينهي', + 'today': 'اليوم', + 'markItems': ['واحد', 'اثنين', 'ثلاثة', 'أربعة', 'خمسة', 'ستة', 'يوم'], + 'yearAndMonth': '${year} سنة ${month} شهر', + }, + 'Cascader': { 'placeholder': 'اختر من فضلك' }, + 'Dialog': { 'ok': 'عرفت' }, + 'DatePicker': { 'tillNow': 'إلى اليوم' }, + 'ErrorBlock': { + 'default': { + 'title': 'تواجه الصفحة بعض المشكلات البسيطة', + 'description': 'حاول لاحقًا', + }, + 'busy': { 'title': 'الازدحام في الأمام', 'description': 'حاول التجديد' }, + 'disconnected': { + 'title': 'شبكة مشغولة', + 'description': 'مرر أصابعك وساعد ف الإصلاح', + }, + 'empty': { + 'title': 'لم أتمكن من العثور على ما تحتاجه', + 'description': 'البحث عن شيء آخر', + }, + }, + 'Form': { + 'required': 'مطلوب', + 'optional': 'اختياري', + 'defaultValidateMessages': { + 'default': 'خطأ في التحقق من صحة الكلمات ${label}', + 'required': 'يرجى إدخال ${label}', + 'enum': '${label} يجب أن يكون واحدًا منهم [ ${enum} ]', + 'whitespace': '${label} لا يمكن أن يكون حرفًا فارغًا', + 'date': { + 'format': '${label} تنسيق التاريخ غير صالح', + 'parse': '${label} لا يمكن تحويله إلى تاريخ', + 'invalid': '${label} تاريخ غير صالح', + }, + 'types': { + 'string': typeTemplate, + 'method': typeTemplate, + 'array': typeTemplate, + 'object': typeTemplate, + 'number': typeTemplate, + 'date': typeTemplate, + 'boolean': typeTemplate, + 'integer': typeTemplate, + 'float': typeTemplate, + 'regexp': typeTemplate, + 'email': typeTemplate, + 'url': typeTemplate, + 'hex': typeTemplate, + }, + 'string': { + 'len': '${label} يجب أن يكون عدد الأحرف ${len}', + 'min': '${label} أحرف على الأقل ${min}', + 'max': '${label} الحد الأقصى لعدد الأحرف ${max}', + 'range': '${label} يجب أن يكون بين ${min} - ${max} حرفًا', + }, + 'number': { + 'len': '${label} يجب أن يساوي ${len}', + 'min': '${label}الحد الأدنى للقيمة هو ${min}', + 'max': '${label}القيمة القصوى هي ${max}', + 'range': '${label} يجب أن يكون بين ${min} - ${max}', + }, + 'array': { + 'len': 'يجب أن يكون ${len} ${label}', + 'min': 'على الأقل ${min} ${label}', + 'max': 'الحد الأقصى ${max} ${label}', + 'range': '${label} يجب أن تكون الكمية بين ${min} - ${max}', + }, + 'pattern': { 'mismatch': '${label} لا يتطابق مع النمط ${pattern}' }, + }, + }, + 'ImageUploader': { 'uploading': 'جارٍ التحميل...', 'upload': 'تحميل' }, + 'InfiniteScroll': { + 'noMore': '-لا يوجد أكثر-', + 'failedToLoad': 'فشل التحميل', + 'retry': 'إعادة التحميل', + }, + 'Input': { 'clear': 'إزالة' }, + 'Mask': { 'name': 'قناع الخلفية' }, + 'Modal': { 'ok': 'عرفت' }, + 'PasscodeInput': { 'name': 'مربع إدخال كلمة المرور' }, + 'PullToRefresh': { + 'pulling': 'اسحب إلى الأسفل للتحديث', + 'canRelease': 'حرر للتحديث على الفور', + 'complete': 'تم التحديث بنجاح', + }, + 'SearchBar': { 'name': 'شريط البحث' }, + 'Slider': { 'name': 'شريط الإدخال المنزلق' }, + 'Stepper': { 'decrease': 'يقلل', 'increase': 'يزيد' }, + 'Switch': { 'name': 'زر الفتح والإغلاق' }, + 'Selector': { 'name': 'اختر مجموعة' }, +}) + +export default arSA diff --git a/src/locales/de-DE.ts b/src/locales/de-DE.ts new file mode 100644 index 0000000000..fb3f957ce9 --- /dev/null +++ b/src/locales/de-DE.ts @@ -0,0 +1,125 @@ +import { mergeLocale } from '../utils/merge-locale' +import { base } from './base' + +const typeTemplate = '${label}ist kein gültiges${type}' + +const deDE = mergeLocale(base, { + 'locale': 'de-DE', + 'common': { + 'confirm': 'Bestätigen', + 'cancel': 'Abbrechen', + 'loading': 'Wird geladen', + 'close': 'Deaktivieren', + }, + 'Calendar': { + 'title': 'Datum auswählen', + 'confirm': 'Bestätigen', + 'start': 'Starten', + 'end': 'Beenden', + 'today': 'Heute', + 'markItems': [ + 'Montag', + 'Dienstag', + 'Mittwoch', + 'Donnerstag', + 'Freitag', + 'Samstag', + 'Tag', + ], + 'yearAndMonth': '${year}Jahr${month}Monat', + }, + 'Cascader': { 'placeholder': 'Bitte auswählen' }, + 'Dialog': { 'ok': 'OK' }, + 'DatePicker': { 'tillNow': 'Bis heute' }, + 'ErrorBlock': { + 'default': { + 'title': 'Es gibt ein kleines Problem auf der Seite', + 'description': 'Versuche Sie es später', + }, + 'busy': { + 'title': 'Stau im Voraus', + 'description': 'Einmal aktualisieren', + }, + 'disconnected': { + 'title': 'Beschäftigtes Internet', + 'description': 'Beweg deine Finger und hilf mit!', + }, + 'empty': { + 'title': 'Sie haben nicht gefunden, was Sie brauchen.', + 'description': 'Finden Sie etwas anderes.', + }, + }, + 'Form': { + 'required': 'Pflichtfeld', + 'optional': 'Optional', + 'defaultValidateMessages': { + 'default': 'Fehler bei der Feldüberprüfung${label}', + 'required': 'Bitte geben ${label}ein', + 'enum': '${label}muss einer von ihnen sein[${enum}]', + 'whitespace': '${label}kann nicht ein Nullzeichen sein', + 'date': { + 'format': '${label}Ungültiges Datumsformat', + 'parse': '${label}kann nicht in ein Datum umgewandelt werden', + 'invalid': '${label}ist ein ungültiges Datum', + }, + 'types': { + 'string': typeTemplate, + 'method': typeTemplate, + 'array': typeTemplate, + 'object': typeTemplate, + 'number': typeTemplate, + 'date': typeTemplate, + 'boolean': typeTemplate, + 'integer': typeTemplate, + 'float': typeTemplate, + 'regexp': typeTemplate, + 'email': typeTemplate, + 'url': typeTemplate, + 'hex': typeTemplate, + }, + 'string': { + 'len': '${label} muss ${len} Zeichen lang sein', + 'min': '${label}kann mindestens ${min} Zeichen haben', + 'max': '${label}kann bis zu${max} Zeichen haben', + 'range': '${label}muss zwischen${min}-${max} Zeichen liegen', + }, + 'number': { + 'len': '${label}Muss gleich${len}sein', + 'min': '${label}Der Mindestwert beträgt${min}', + 'max': '${label}Der Höchstwert beträgt ${max}', + 'range': '${label}muss zwischen${min}-${max} liegen', + }, + 'array': { + 'len': 'Muss${len}sein${label}', + 'min': 'Mindestens${min}${label}', + 'max': 'Bis zu${max}${label}', + 'range': '${label}Die Anzahl muss zwischen${min}-${max} liegen', + }, + 'pattern': { + 'mismatch': '${label}stimmt nicht mit dem Muster überein${pattern}', + }, + }, + }, + 'ImageUploader': { 'uploading': 'Beim Hochladen', 'upload': 'Hochladen' }, + 'InfiniteScroll': { + 'noMore': "Das war's", + 'failedToLoad': 'Hochladen Fehlgeschlagen', + 'retry': 'Erneut laden', + }, + 'Input': { 'clear': 'Löschen' }, + 'Mask': { 'name': 'Hintergrundmaske' }, + 'Modal': { 'ok': 'OK' }, + 'PasscodeInput': { 'name': 'Passwort-Eingabefeld' }, + 'PullToRefresh': { + 'pulling': 'Nach unten zum Aktualisieren ziehen', + 'canRelease': 'Loslassen zum sofortige aktualisieren', + 'complete': 'Erfolgreiche Aktualisierung', + }, + 'SearchBar': { 'name': 'Suchfeld' }, + 'Slider': { 'name': 'Schieberegler für die Eingabe' }, + 'Stepper': { 'decrease': 'Reduzieren', 'increase': 'Erhöhen' }, + 'Switch': { 'name': 'Schalter' }, + 'Selector': { 'name': 'Gruppe auswählen' }, +}) + +export default deDE diff --git a/src/locales/ms-MY.ts b/src/locales/ms-MY.ts new file mode 100644 index 0000000000..8c37d8d668 --- /dev/null +++ b/src/locales/ms-MY.ts @@ -0,0 +1,118 @@ +import { mergeLocale } from '../utils/merge-locale' +import { base } from './base' + +const typeTemplate = '${label} Bukan satu yabg sah ${type}' + +const msMY = mergeLocale(base, { + 'locale': 'ms-MY', + 'common': { + 'confirm': 'OK', + 'cancel': 'Batal', + 'loading': 'Memuatkan', + 'close': 'Tutup', + }, + 'Calendar': { + 'title': 'Pemilihan tarikh', + 'confirm': 'Ok', + 'start': 'Mula', + 'end': 'Tamat', + 'today': 'Hari ini', + 'markItems': ['Satu', 'Dua', 'Tiga', 'Empat', 'Lima', 'Enam', 'Hari'], + 'yearAndMonth': 'Tahun${year} bulan ${month}', + }, + 'Cascader': { 'placeholder': 'Sila pilih' }, + 'Dialog': { 'ok': 'Faham' }, + 'DatePicker': { 'tillNow': 'Sehingga kini' }, + 'ErrorBlock': { + 'default': { + 'title': 'Halaman mengalami beberapa isu kecil', + 'description': 'Cuba kemudian', + }, + 'busy': { + 'title': 'Kesesakan di hadapan', + 'description': 'Muat semula dan cuba', + }, + 'disconnected': { + 'title': 'Rangkaian agak sibuk', + 'description': 'Untuk membantu membaiki, gerakkan jari anda.', + }, + 'empty': { + 'title': 'Tidak menemui apa yang anda perlukan', + 'description': 'Cari yang lain', + }, + }, + 'Form': { + 'required': 'Wajib', + 'optional': 'Pilihan', + 'defaultValidateMessages': { + 'default': 'Ralat pengesahan medan ${label}', + 'required': 'Sila masukkan ${label}', + 'enum': '${label} mestilah salah satu daripada [${enum}]', + 'whitespace': '${label} Tidak boleh menjadi watak nol', + 'date': { + 'format': 'Format tarikh ${label} tidak sah', + 'parse': '${label} tidak boleh ditukar kepada tarikh', + 'invalid': '${label} Adalah tarikh yang tidak sah', + }, + 'types': { + 'string': typeTemplate, + 'method': typeTemplate, + 'array': typeTemplate, + 'object': typeTemplate, + 'number': typeTemplate, + 'date': typeTemplate, + 'boolean': typeTemplate, + 'integer': typeTemplate, + 'float': typeTemplate, + 'regexp': typeTemplate, + 'email': typeTemplate, + 'url': typeTemplate, + 'hex': typeTemplate, + }, + 'string': { + 'len': '${label} Mestilah ${len} aksara', + 'min': '${label} Sekurang-kurangnya ${min} aksara', + 'max': '${label}Maksimum ${max} aksara', + 'range': '${label} Mesti antara ${min}-${max} aksara', + }, + 'number': { + 'len': '${label} mesti sama dengan ${len}', + 'min': 'Nilai minimum ${label} ialah ${min}', + 'max': 'Nilai maksimum ${label} ialah ${max}', + 'range': '${label}Mesti antara ${min}-${max}', + }, + 'array': { + 'len': 'Mesti ${len} ${label}', + 'min': 'Minimum ${min} ${label}', + 'max': 'Maksimum ${max} ${label}', + 'range': '${label}Kuantiti mestilah antara ${min}-${max}', + }, + 'pattern': { 'mismatch': '${label}Tidak sepadan dengan model${pattern}' }, + }, + }, + 'ImageUploader': { + 'uploading': 'Sedang memuat naik...', + 'upload': 'memuat naik', + }, + 'InfiniteScroll': { + 'noMore': 'Tiada lagi', + 'failedToLoad': 'Gagal dimuatkan.', + 'retry': 'Muat semula', + }, + 'Input': { 'clear': 'Bersihkan' }, + 'Mask': { 'name': 'lapisan topeng latar belakang' }, + 'Modal': { 'ok': 'Faham' }, + 'PasscodeInput': { 'name': 'Kotak input kata laluan' }, + 'PullToRefresh': { + 'pulling': 'Tarik ke bawah untuk muat semula', + 'canRelease': 'Lepaskan untuk memuatkan semula', + 'complete': 'Muat semula selesai', + }, + 'SearchBar': { 'name': 'Kotak carian' }, + 'Slider': { 'name': 'Bar input gelongsor' }, + 'Stepper': { 'decrease': 'Menurun', 'increase': 'Meningkat' }, + 'Switch': { 'name': 'Suis' }, + 'Selector': { 'name': 'Pilih kumpulan' }, +}) + +export default msMY diff --git a/src/locales/vi-VN.ts b/src/locales/vi-VN.ts new file mode 100644 index 0000000000..8542b70f0f --- /dev/null +++ b/src/locales/vi-VN.ts @@ -0,0 +1,112 @@ +import { mergeLocale } from '../utils/merge-locale' +import { base } from './base' + +const typeTemplate = '${label} không phải là một ${type} hợp lệ' + +const viVN = mergeLocale(base, { + 'locale': 'vi-VN', + 'common': { + 'confirm': 'Chắc chắn', + 'cancel': 'Hủy', + 'loading': 'Đang tải', + 'close': 'Đóng', + }, + 'Calendar': { + 'title': 'Chọn ngày', + 'confirm': 'Xác nhận', + 'start': 'Bắt đầu', + 'end': 'Kết thúc', + 'today': 'Hôm nay', + 'markItems': ['Một', 'Hai', 'Ba', 'Bốn', 'Năm', 'Sáu', 'Ngày'], + 'yearAndMonth': 'Tháng ${month} năm ${year}', + }, + 'Cascader': { 'placeholder': 'Vui lòng lựa chọn' }, + 'Dialog': { 'ok': 'OK' }, + 'DatePicker': { 'tillNow': 'Đến nay' }, + 'ErrorBlock': { + 'default': { + 'title': 'Trang đang gặp một số vấn đề nhỏ', + 'description': 'Đợi chút rồi thử', + }, + 'busy': { 'title': 'Ùn tắc phía trước', 'description': 'Thử quét mới' }, + 'disconnected': { + 'title': 'Mạng đang bận', + 'description': 'Chạm khẽ để chỉnh sửa', + }, + 'empty': { + 'title': 'Không tìm thấy thứ bạn cần', + 'description': 'Tìm cái khác', + }, + }, + 'Form': { + 'required': 'Bắt buộc', + 'optional': 'Tùy chọn', + 'defaultValidateMessages': { + 'default': 'Lỗi xác thực trường ${label}', + 'required': 'Vui lòng nhập ${label}', + 'enum': '${label} phải là một trong [${enum}]', + 'whitespace': '${label} không được là ký tự trống', + 'date': { + 'format': '${label}Định dạng ngày tháng không còn hiệu lực', + 'parse': '${label} Không thể chuyển đổi thành ngày', + 'invalid': '${label} là một ngày không hợp lệ', + }, + 'types': { + 'string': typeTemplate, + 'method': typeTemplate, + 'array': typeTemplate, + 'object': typeTemplate, + 'number': typeTemplate, + 'date': typeTemplate, + 'boolean': typeTemplate, + 'integer': typeTemplate, + 'float': typeTemplate, + 'regexp': typeTemplate, + 'email': typeTemplate, + 'url': typeTemplate, + 'hex': typeTemplate, + }, + 'string': { + 'len': '${label} phải là ${len} ký tự', + 'min': '${label} tối thiểu ${min} ký tự', + 'max': '${label} tối đa ${max} ký tự', + 'range': '${label} phải ở giữa chữ ${min} - ${max}', + }, + 'number': { + 'len': '${label} phải bằng ${len}', + 'min': '${label} giá trị tối thiểu là ${min}', + 'max': '${label} giá trị tối đa là ${max}', + 'range': '${label} phải ở giữa ${min} - ${max}', + }, + 'array': { + 'len': 'Phải là ${len} chiếc ${label}', + 'min': 'Tối thiểu ${min} chiếc ${label}', + 'max': 'Tối đa ${max} chiếc ${label}', + 'range': '${label} số lượng phải ở giữa ${min} - ${max}', + }, + 'pattern': { 'mismatch': '${label} không khớp với mẫu ${pattern}' }, + }, + }, + 'ImageUploader': { 'uploading': 'Đang tải lên...', 'upload': 'Tải lên' }, + 'InfiniteScroll': { + 'noMore': 'Hết rồi bạn ơi', + 'failedToLoad': 'Tải xuống thất bại', + 'retry': 'Tải lại', + }, + 'Input': { 'clear': 'Xóa' }, + 'Mask': { 'name': 'Nền tối' }, + 'Modal': { 'ok': 'OK' }, + 'PasscodeInput': { 'name': 'Khung nhập mật khẩu' }, + 'PullToRefresh': { + 'pulling': 'Kéo xuống để làm mới', + 'canRelease': 'Thả ra để làm mới', + 'complete': 'Làm mới thành công', + }, + 'SearchBar': { 'name': 'Khung tìm kiếm' }, + 'Slider': { 'name': 'Thanh nhập liệu trượt' }, + 'Stepper': { 'decrease': 'Giảm', 'increase': 'Tăng' }, + 'Switch': { 'name': 'Bật tắt' }, + 'Selector': { 'name': 'Chọn nhóm' }, +}) + +export default viVN From fc4bdb9d86d9fcf0b1f859d432edeac43908af51 Mon Sep 17 00:00:00 2001 From: qingyan Date: Thu, 23 May 2024 12:48:47 +0800 Subject: [PATCH 2/5] feat(i18n): add in-ID and update others --- docs/guide/i18n.en.md | 1 + docs/guide/i18n.zh.md | 1 + .../tests/config-provider.test.tsx | 2 + src/locales/ar-SA.ts | 4 +- src/locales/de-DE.ts | 14 +-- src/locales/es-ES.ts | 4 +- src/locales/fr-FR.ts | 2 +- src/locales/in-ID.ts | 115 ++++++++++++++++++ src/locales/ja-JP.ts | 4 +- src/locales/th-TH.ts | 4 +- 10 files changed, 131 insertions(+), 20 deletions(-) create mode 100644 src/locales/in-ID.ts diff --git a/docs/guide/i18n.en.md b/docs/guide/i18n.en.md index f6b96d0f9a..6751a2ace9 100644 --- a/docs/guide/i18n.en.md +++ b/docs/guide/i18n.en.md @@ -30,6 +30,7 @@ The following languages are currently supported: | Japanese | ja-JP | | Kazakh | kk-KZ | | Indonesian | id-ID | +| Indonesian(old form) | in-ID | | Italian | it-IT | | Danish | da-DK | | Norwegian (Bokmål) | nb-NO | diff --git a/docs/guide/i18n.zh.md b/docs/guide/i18n.zh.md index 491fd8607b..bbb4600b15 100644 --- a/docs/guide/i18n.zh.md +++ b/docs/guide/i18n.zh.md @@ -29,6 +29,7 @@ return ( | 日语 | ja-JP | | 哈萨克语 | kk-KZ | | 印度尼西亚语 | id-ID | +| 印度尼西亚语(旧版) | in-ID | | 意大利语 | it-IT | | 丹麦语 | da-DK | | 挪威 | nb-NO | diff --git a/src/components/config-provider/tests/config-provider.test.tsx b/src/components/config-provider/tests/config-provider.test.tsx index b8919863db..1db12cbfcf 100644 --- a/src/components/config-provider/tests/config-provider.test.tsx +++ b/src/components/config-provider/tests/config-provider.test.tsx @@ -21,6 +21,7 @@ import faIR from '../../../locales/fa-IR' import frFR from '../../../locales/fr-FR' import huHU from '../../../locales/hu-HU' import idID from '../../../locales/id-ID' +import inID from '../../../locales/in-ID' import itIT from '../../../locales/it-IT' import jaJP from '../../../locales/ja-JP' import kkKZ from '../../../locales/kk-KZ' @@ -62,6 +63,7 @@ const locales = [ arSA, ptBR, viVN, + inID, ] describe('ConfigProvider', () => { diff --git a/src/locales/ar-SA.ts b/src/locales/ar-SA.ts index b648972051..cfa5fe5cfb 100644 --- a/src/locales/ar-SA.ts +++ b/src/locales/ar-SA.ts @@ -21,7 +21,7 @@ const arSA = mergeLocale(base, { 'yearAndMonth': '${year} سنة ${month} شهر', }, 'Cascader': { 'placeholder': 'اختر من فضلك' }, - 'Dialog': { 'ok': 'عرفت' }, + 'Dialog': { 'ok': 'فهمت' }, 'DatePicker': { 'tillNow': 'إلى اليوم' }, 'ErrorBlock': { 'default': { @@ -95,7 +95,7 @@ const arSA = mergeLocale(base, { }, 'Input': { 'clear': 'إزالة' }, 'Mask': { 'name': 'قناع الخلفية' }, - 'Modal': { 'ok': 'عرفت' }, + 'Modal': { 'ok': 'فهمت' }, 'PasscodeInput': { 'name': 'مربع إدخال كلمة المرور' }, 'PullToRefresh': { 'pulling': 'اسحب إلى الأسفل للتحديث', diff --git a/src/locales/de-DE.ts b/src/locales/de-DE.ts index fb3f957ce9..447d0395b7 100644 --- a/src/locales/de-DE.ts +++ b/src/locales/de-DE.ts @@ -17,19 +17,11 @@ const deDE = mergeLocale(base, { 'start': 'Starten', 'end': 'Beenden', 'today': 'Heute', - 'markItems': [ - 'Montag', - 'Dienstag', - 'Mittwoch', - 'Donnerstag', - 'Freitag', - 'Samstag', - 'Tag', - ], + 'markItems': ['I', 'II', 'III', 'IV', 'V', 'Sechs', 'Tag'], 'yearAndMonth': '${year}Jahr${month}Monat', }, 'Cascader': { 'placeholder': 'Bitte auswählen' }, - 'Dialog': { 'ok': 'OK' }, + 'Dialog': { 'ok': 'Ich weiß.' }, 'DatePicker': { 'tillNow': 'Bis heute' }, 'ErrorBlock': { 'default': { @@ -108,7 +100,7 @@ const deDE = mergeLocale(base, { }, 'Input': { 'clear': 'Löschen' }, 'Mask': { 'name': 'Hintergrundmaske' }, - 'Modal': { 'ok': 'OK' }, + 'Modal': { 'ok': 'Ich weiß.' }, 'PasscodeInput': { 'name': 'Passwort-Eingabefeld' }, 'PullToRefresh': { 'pulling': 'Nach unten zum Aktualisieren ziehen', diff --git a/src/locales/es-ES.ts b/src/locales/es-ES.ts index b7fc56b8b9..6177551027 100644 --- a/src/locales/es-ES.ts +++ b/src/locales/es-ES.ts @@ -18,7 +18,7 @@ const esES = mergeLocale(base, { placeholder: 'Seleccionando', }, Dialog: { - ok: 'OK', + ok: 'Entendido', }, ErrorBlock: { default: { @@ -96,7 +96,7 @@ const esES = mergeLocale(base, { name: 'Máscara', }, Modal: { - ok: 'OK', + ok: 'Entendido', }, PullToRefresh: { pulling: 'Desplácese hacia abajo para refrescar', diff --git a/src/locales/fr-FR.ts b/src/locales/fr-FR.ts index becc248234..9cacf81dad 100644 --- a/src/locales/fr-FR.ts +++ b/src/locales/fr-FR.ts @@ -6,7 +6,7 @@ const typeTemplate = '${label}Pas un valide${type}' const frFR = mergeLocale(base, { locale: 'fr-FR', common: { - confirm: 'Valider', + confirm: 'Activer', cancel: 'Annuler', loading: 'Chargement', }, diff --git a/src/locales/in-ID.ts b/src/locales/in-ID.ts new file mode 100644 index 0000000000..8a09ce9870 --- /dev/null +++ b/src/locales/in-ID.ts @@ -0,0 +1,115 @@ +import { mergeLocale } from '../utils/merge-locale' +import { base } from './base' + +const typeTemplate = '${label} bukan ${type} yang valid' + +const inID = mergeLocale(base, { + locale: 'in-ID', + common: { + confirm: 'Yakin', + cancel: 'Batal ', + loading: 'memuat', + close: 'Tutup', + }, + Calendar: { + title: 'Pilih Tanggal', + confirm: 'OK', + start: 'Mulai', + end: 'Selesai', + today: 'Hari Ini', + markItems: ['Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu'], + yearAndMonth: '${year} Tahun ${month} Bulan', + }, + Cascader: { placeholder: 'Silahkan Pilih' }, + Dialog: { ok: 'Saya mendapatkannya' }, + DatePicker: { tillNow: 'Sampai sekarang' }, + ErrorBlock: { + default: { + title: 'Halaman mengalami beberapa permasalahan kecil', + description: 'Coba lagi nanti', + }, + busy: { + title: 'kepadatan diawal', + description: 'Coba untuk menyegarkan', + }, + disconnected: { + title: 'jaringan sedikit sibuk', + description: 'Gerakkan jari Anda untuk membantu memperbaiki', + }, + empty: { + title: 'Itu tidak menemukan apa yang Anda butuhkan', + description: 'Silahkan cari yang lain', + }, + }, + Form: { + required: 'Diperlukan', + optional: 'opsional untuk diisi', + defaultValidateMessages: { + default: 'Kesalahan validasi bidang ${label}', + required: 'Harap masukkan ${label}', + enum: '${label} harus salah satu dari [${enum}]', + whitespace: '${label} tidak boleh berupa karakter kosong', + date: { + format: 'Format tanggal ${label} tidak valid', + parse: '${label} tidak dapat dikonversi ke tanggal', + invalid: '${label} adalah tanggal yang tidak valid', + }, + types: { + string: typeTemplate, + method: typeTemplate, + array: typeTemplate, + object: typeTemplate, + number: typeTemplate, + date: typeTemplate, + boolean: typeTemplate, + integer: typeTemplate, + float: typeTemplate, + regexp: typeTemplate, + email: typeTemplate, + url: typeTemplate, + hex: typeTemplate, + }, + string: { + len: '${label} harus berupa ${len} karakter', + min: '${label} Minimal ${min} karakter', + max: '${label}Maksimum ${max} karakter', + range: '${label} harus antara ${min}-${max} karakter', + }, + number: { + len: '${label} harus sama dengan ${len}', + min: 'Nilai minimum ${label} adalah ${min}', + max: '${label} memiliki nilai maksimum ${max}', + range: '${label} harus antara ${min}-${max}', + }, + array: { + len: 'Harus ${len} ${label}', + min: 'Minimal ${min} ${label}', + max: 'Hingga ${max} ${label}', + range: 'Jumlah ${label} harus antara ${min}-${max}', + }, + pattern: { mismatch: '${label} tidak cocok dengan pola ${pattern}' }, + }, + }, + ImageUploader: { uploading: 'mengunggah...', upload: 'diunggah' }, + InfiniteScroll: { + noMore: 'tidak ada lagi', + failedToLoad: 'Gagal memuat', + retry: 'memuat ulang', + }, + Input: { clear: 'Hapus' }, + Mask: { name: 'lapisan pelindung' }, + Modal: { ok: 'Saya mendapatkannya' }, + PasscodeInput: { name: 'Kotak kata sandi' }, + PullToRefresh: { + pulling: 'Tarik ke bawah untuk menyegarkan', + canRelease: 'Lepaskan untuk menyegarkan segera', + complete: 'Segarkan berhasil', + }, + SearchBar: { name: 'Bilah Pencarian' }, + Slider: { name: 'Penggeser' }, + Stepper: { decrease: 'mengurangi', increase: 'meningkat' }, + Switch: { name: 'Mengalihkan' }, + Selector: { name: 'Grup pilih' }, +}) + +export default inID diff --git a/src/locales/ja-JP.ts b/src/locales/ja-JP.ts index 564d729d44..96d150e4a7 100644 --- a/src/locales/ja-JP.ts +++ b/src/locales/ja-JP.ts @@ -18,7 +18,7 @@ const jaJP = mergeLocale(base, { placeholder: '選択下さい', }, Dialog: { - ok: 'わかりました', + ok: '了解', }, ErrorBlock: { default: { @@ -105,7 +105,7 @@ const jaJP = mergeLocale(base, { name: 'マスク', }, Modal: { - ok: 'わかりました', + ok: '了解', }, PasscodeInput: { name: 'パスコード入力', diff --git a/src/locales/th-TH.ts b/src/locales/th-TH.ts index e27ce81bdf..452b66b939 100644 --- a/src/locales/th-TH.ts +++ b/src/locales/th-TH.ts @@ -32,7 +32,7 @@ const thTH = mergeLocale(base, { placeholder: 'เลือก', }, Dialog: { - ok: 'โอเค', + ok: 'ฉันรู้แล้ว', }, DatePicker: { tillNow: 'จนถึงตอนนี้', @@ -122,7 +122,7 @@ const thTH = mergeLocale(base, { name: 'มาสก์', }, Modal: { - ok: 'ตกลง', + ok: 'ฉันรู้แล้ว', }, PasscodeInput: { name: 'ป้อนรหัสผ่าน', From 337c1b6f90d6597370bf835746a71e7c19ff87d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Mon, 27 May 2024 10:26:21 +0800 Subject: [PATCH 3/5] test: update snapshot --- .../config-provider.test.tsx.snap | 4668 ++++++++++++++++- 1 file changed, 4656 insertions(+), 12 deletions(-) diff --git a/src/components/config-provider/tests/__snapshots__/config-provider.test.tsx.snap b/src/components/config-provider/tests/__snapshots__/config-provider.test.tsx.snap index 0960fc97c4..1eff27f4e7 100644 --- a/src/components/config-provider/tests/__snapshots__/config-provider.test.tsx.snap +++ b/src/components/config-provider/tests/__snapshots__/config-provider.test.tsx.snap @@ -9475,32 +9475,32 @@ exports[`ConfigProvider should display the text as de-DE 1`] = `
- Montag + I
- Dienstag + II
- Mittwoch + III
- Donnerstag + IV
- Freitag + V
- Samstag + Sechs
- Montag + I
- Dienstag + II
- Mittwoch + III
- Donnerstag + IV
- Freitag + V
- Samstag + Sechs
`; +exports[`ConfigProvider should display the text as in-ID 1`] = ` +
+
+ +
+
+ Minggu +
+
+ Senin +
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 29 +
+
+
+
+
+
+ 30 +
+
+
+
+
+
+ 31 +
+
+
+
+
+
+
+ 2022 Tahun 9 Bulan +
+
+
+
+
+
+
+
+
+ 1 +
+
+
+
+
+
+ 2 +
+
+
+
+
+
+ 3 +
+
+
+
+
+
+ 4 +
+
+
+
+
+
+ 5 +
+
+
+
+
+
+ 6 +
+
+
+
+
+
+ 7 +
+
+
+
+
+
+ 8 +
+
+
+
+
+
+ 9 +
+
+
+
+
+
+ 10 +
+
+
+
+
+
+ 11 +
+
+
+
+
+
+ 12 +
+
+
+
+
+
+ 13 +
+
+
+
+
+
+ 14 +
+
+
+
+
+
+ 15 +
+
+
+
+
+
+ 16 +
+
+
+
+
+
+ 17 +
+
+
+
+
+
+ 18 +
+
+
+
+
+
+ 19 +
+
+
+
+
+
+ 20 +
+
+
+
+
+
+ 21 +
+
+
+
+
+
+ 22 +
+
+
+
+
+
+ 23 +
+
+
+
+
+
+ 24 +
+
+
+
+
+
+ 25 +
+
+
+
+
+
+ 26 +
+
+
+
+
+
+ 27 +
+
+
+
+
+
+ 28 +
+
+
+
+
+
+ 29 +
+
+
+
+
+
+ 30 +
+
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ Halaman mengalami beberapa permasalahan kecil +
+
+ Coba lagi nanti +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+ + + +
+ +
+ + + + + + + + + + +
+
+
+
+ + + + + + + + + + + + + +
+
+
+
+
+`; + exports[`ConfigProvider should display the text as it-IT 1`] = `
Date: Mon, 27 May 2024 11:22:22 +0800 Subject: [PATCH 4/5] test: fix test case --- src/components/dialog/tests/dialog.test.tsx | 41 ++++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/components/dialog/tests/dialog.test.tsx b/src/components/dialog/tests/dialog.test.tsx index 5536f77179..213e409ada 100644 --- a/src/components/dialog/tests/dialog.test.tsx +++ b/src/components/dialog/tests/dialog.test.tsx @@ -1,17 +1,17 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ +import { act } from '@testing-library/react' import React from 'react' import { + fireEvent, render, + screen, testA11y, - fireEvent, + waitFakeTimers, waitFor, waitForElementToBeRemoved, - screen, - waitFakeTimers, } from 'testing' import Dialog, { DialogAlertProps } from '..' -import { act } from '@testing-library/react' const classPrefix = `adm-dialog` @@ -121,6 +121,8 @@ describe('Dialog', () => { }) test('wait for confirm to complete', async () => { + jest.useFakeTimers() + const fn = jest.fn() const Confirm = () => ( - ) - - render() - - // First click to open - const btn = screen.getByRole('button', { name: 'btn' }) - fireEvent.click(btn) - await waitFakeTimers() - - // Click confirm - fireEvent.click(screen.getByRole('button', { name: '确定' })) - expect(fn).not.toHaveBeenCalled() - await waitFakeTimers() - expect(fn).toHaveBeenCalledWith(true) - - // Clean up - await waitFakeTimers() - fn.mockRestore() - - // Second click - fireEvent.click(btn) - await waitFakeTimers() - - // Click cancel - fireEvent.click(screen.getByRole('button', { name: '取消' })) - expect(fn).not.toHaveBeenCalled() - await waitFakeTimers() - expect(fn).toHaveBeenCalledWith(false) - - jest.useRealTimers() + describe('wait for confirm to complete', () => { + function testFn(button: string, result: boolean) { + test(`wait for confirm to complete (${String(result)})`, async () => { + jest.useFakeTimers() + + const fn = jest.fn() + const Confirm = () => ( + + ) + + render() + + // First click to open + const btn = screen.getByRole('button', { name: 'btn' }) + fireEvent.click(btn) + await waitFakeTimers() + + // Click confirm + fireEvent.click(screen.getByRole('button', { name: button })) + expect(fn).not.toHaveBeenCalled() + await waitFakeTimers() + expect(fn).toHaveBeenCalledWith(result) + + jest.useRealTimers() + }) + } + + testFn('确定', true) + testFn('取消', false) }) test('custom actions', async () => {