From fdb1ab1d410d226c3e89b3e727b6886487a1b491 Mon Sep 17 00:00:00 2001 From: Odai Hatem Abu Gaith Date: Thu, 29 Aug 2019 12:34:28 +0400 Subject: [PATCH 1/3] Adding Arabic to localization --- LOCALIZATION.md | 1 + .../component/src/Localization/Localize.js | 8 +- packages/component/src/Localization/ar-AR.js | 95 +++++++++++++++++++ packages/embed/src/locale.js | 1 + packages/embed/src/locale.spec.js | 3 + packages/playground/src/App.js | 1 + 6 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 packages/component/src/Localization/ar-AR.js diff --git a/LOCALIZATION.md b/LOCALIZATION.md index 3cacf4525d..b226270afa 100644 --- a/LOCALIZATION.md +++ b/LOCALIZATION.md @@ -6,6 +6,7 @@ If you want to help to translate Web Chat to different language, please submit a | Language code | Translator | | ------------- | ---------------------------------------------------------- | +| ar-AR | Odai Hatem AbuGaith | | bg-bg | @kalin.krustev | | cs-cz | @msimecek | | da-dk | @Simon_lfr, Thomas Skødt Andersen | diff --git a/packages/component/src/Localization/Localize.js b/packages/component/src/Localization/Localize.js index 0620bd65a1..acef534a4d 100644 --- a/packages/component/src/Localization/Localize.js +++ b/packages/component/src/Localization/Localize.js @@ -4,6 +4,7 @@ import connectToWebChat from '../connectToWebChat'; import getLocaleString from './getLocaleString'; +import bgBG from './ar-AR'; import bgBG from './bg-BG'; import csCZ from './cs-CZ'; import daDK from './da-DK'; @@ -32,8 +33,9 @@ import zhYUE from './zh-YUE'; function normalizeLanguage(language) { language = language.toLowerCase(); - - if (language.startsWith('bg')) { + if (language.startsWith('ar')) { + return 'ar-AR'; + } else if (language.startsWith('bg')) { return 'bg-BG'; } else if (language.startsWith('cs')) { return 'cs-CZ'; @@ -88,6 +90,8 @@ function normalizeLanguage(language) { function getStrings(language) { switch (normalizeLanguage(language || '')) { + case 'ar-AR': + return arAR; case 'bg-BG': return bgBG; case 'cs-CZ': diff --git a/packages/component/src/Localization/ar-AR.js b/packages/component/src/Localization/ar-AR.js new file mode 100644 index 0000000000..50b2ba849c --- /dev/null +++ b/packages/component/src/Localization/ar-AR.js @@ -0,0 +1,95 @@ +/* eslint no-magic-numbers: ["error", { "ignore": [1, 5, 24, 48, 60000, 3600000] }] */ + +import getLocaleString from './getLocaleString'; + +function xMinutesAgo(dateStr) { + const date = new Date(dateStr); + const dateTime = date.getTime(); + + if (isNaN(dateTime)) { + return dateStr; + } + + const now = Date.now(); + const deltaInMs = now - dateTime; + const deltaInMinutes = Math.floor(deltaInMs / 60000); + const deltaInHours = Math.floor(deltaInMs / 3600000); + + if (deltaInMinutes < 1) { + return 'حالياً'; + } else if (deltaInMinutes === 1) { + return 'منذ دقيقة'; + } else if (deltaInHours < 1) { + return `${deltaInMinutes} minutes ago`; + } else if (deltaInHours === 1) { + return `منذ ساعة`; + } else if (deltaInHours < 5) { + return `${deltaInHours} hours ago`; + } else if (deltaInHours <= 24) { + return `اليوم`; + } else if (deltaInHours <= 48) { + return `الامس`; + } + return getLocaleString(date, 'ar-AR'); +} + +function botSaidSomething(avatarInitials, text) { + return `Bot ${avatarInitials} said, ${text}`; +} + +function downloadFileWithFileSize(downloadFileText, fileName, size) { + // Full text should read: "Download file of size " + return `${downloadFileText} ${fileName} of size ${size}`; +} + +function uploadFileWithFileSize(fileName, size) { + return `${fileName} of size ${size}`; +} + +function userSaidSomething(avatarInitials, text) { + return `User ${avatarInitials} said, ${text}`; +} + +export default { + CONNECTED_NOTIFICATION: 'متصل', + FAILED_CONNECTION_NOTIFICATION: 'غير قادر على الاتصال.', + INITIAL_CONNECTION_NOTIFICATION: 'اتصال ...', + INTERRUPTED_CONNECTION_NOTIFICATION: 'حدث انقطاع في الشبكة. إعادة اتصال ... ', + RENDER_ERROR_NOTIFICATION: 'Render error. Please check the console or contact the bot developer.', + // Do not localize {Retry}; it is a placeholder for "Retry". English translation should be, "Send failed. Retry." + SEND_FAILED_KEY: `فشل إرسال. {Retry}.`, + SLOW_CONNECTION_NOTIFICATION: 'يستغرق وقتا أطول من المعتاد للاتصال.', + 'Bot said something': botSaidSomething, + 'User said something': userSaidSomething, + 'X minutes ago': xMinutesAgo, + // '[File of type '%1']': '[File of type '%1']", + // '[Unknown Card '%1']': '[Unknown Card '%1']', + 'Adaptive Card parse error': 'Adaptive Card parse error', + 'Adaptive Card render error': 'Adaptive Card render error', + BotSent: 'تم الارسال: ', + Chat: 'محادثة', + 'Download file': 'تحميل الملف', + DownloadFileWithFileSize: downloadFileWithFileSize, + ErrorMessage: 'خطأ', + 'Microphone off': 'الميكروفون مغلق', + 'Microphone on': 'الميكروفون يعمل', + Left: 'يسار', + 'Listening…': 'الاستماع ...', + 'New messages': 'رسائل جديدة', + Retry: 'حاول مرة اخرى', + Right: 'يمين', + Send: 'ارسل', + Sending: 'ارسال', + SendStatus: 'حالة الارسال: ', + SentAt: 'ارسلت ب', + Speak: 'تكلم', + 'Starting…': 'بداية ... ', + Tax: 'ضريبة', + Total: 'كلياً', + 'Type your message': 'اكتب سؤالك', + TypingIndicator: 'عرض مؤشر الكتابة', + 'Upload file': 'تحميل ملف', + UploadFileWithFileSize: uploadFileWithFileSize, + UserSent: 'ارسل المستخدم:', + VAT: 'ضريبة' +}; diff --git a/packages/embed/src/locale.js b/packages/embed/src/locale.js index 9ed10c1b63..5dd092c5c2 100644 --- a/packages/embed/src/locale.js +++ b/packages/embed/src/locale.js @@ -24,6 +24,7 @@ const AZURE_LOCALE_PATTERN = /^(([a-z]{2})(-[a-z]{2,})?)\.([a-z]{2})/; const JAVASCRIPT_LOCALE_PATTERN = /^([a-z]{2})-([A-Z]{2,})?$/; const AZURE_LOCALE_MAPPING = { + ar: 'ar-AR', bg: 'bg-BG', cs: 'cs-CZ', de: 'de-DE', diff --git a/packages/embed/src/locale.spec.js b/packages/embed/src/locale.spec.js index efc83db23f..6edcf86b84 100644 --- a/packages/embed/src/locale.spec.js +++ b/packages/embed/src/locale.spec.js @@ -4,6 +4,9 @@ test('Normalizing "en.en-us"', () => { expect(normalize('en.en-us')).toBe('en-US'); }); +test('Normalizing "ar.ar-ar"', () => { + expect(normalize('ar.ar-ar')).toBe('ar-AR'); +}); test('Normalizing "bg.bg-bg"', () => { expect(normalize('bg.bg-bg')).toBe('bg-BG'); }); diff --git a/packages/playground/src/App.js b/packages/playground/src/App.js index 2c841a6150..5135fdff2b 100644 --- a/packages/playground/src/App.js +++ b/packages/playground/src/App.js @@ -444,6 +444,7 @@ const App = ({ store }) => { Language