Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Arabic localization support #2593

Merged
merged 24 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d6c9e3b
Adding Arabic localization support
midineo Nov 13, 2019
745e19d
Merge branch 'master' into master
corinagum Nov 14, 2019
a524978
Merge branch 'master' into master
corinagum Nov 15, 2019
5120514
Merge branch 'master' into master
midineo Nov 20, 2019
ea5bb8b
Merge branch 'master' into master
corinagum Nov 20, 2019
6a7d302
Update packages/component/src/Localization/Localize.js
midineo Nov 21, 2019
efa2a30
Update packages/component/src/Localization/Localize.js
midineo Nov 21, 2019
9d02f91
Update packages/component/src/Localization/ar-EG.js
midineo Nov 21, 2019
0ed2ba8
Update packages/component/src/Localization/ar-EG.js
midineo Nov 21, 2019
e09d9d5
Update packages/component/src/Localization/ar-EG.js
midineo Nov 21, 2019
f626ee1
Update packages/component/src/Localization/ar-EG.js
midineo Nov 21, 2019
b1cd93c
Update packages/component/src/Localization/Localize.js
midineo Nov 21, 2019
21b7add
Update packages/component/src/Localization/Localize.js
midineo Nov 21, 2019
a0dd7e4
Merge remote-tracking branch 'upstream/master'
midineo Nov 21, 2019
cb33bca
Applying Review comments
midineo Nov 21, 2019
b4b0f57
adding Arabic Language entry
midineo Nov 21, 2019
51c717a
Merge branch 'master' into master
midineo Nov 21, 2019
f865adc
Merge branch 'master' of https://github.com/midineo/BotFramework-WebChat
midineo Nov 21, 2019
af61613
Merge branch 'master' into master
corinagum Nov 21, 2019
55b8c47
removing unneeded comments
midineo Nov 24, 2019
c95a8cf
Merge branch 'master' of https://github.com/midineo/BotFramework-WebChat
midineo Nov 24, 2019
05f625a
Merge branch 'master' into master
midineo Nov 24, 2019
9bd202c
Merge branch 'master' into master
corinagum Nov 25, 2019
fa04915
Merge branch 'master' into master
corinagum Nov 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LOCALIZATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ If you want to help to translate Web Chat to different language, please submit a

| Language code | Translator |
| ------------- | ---------------------------------------------------------- |
| ar-EG | @midineo |
| bg-bg | @kalin.krustev |
| cs-cz | @msimecek |
| da-dk | @Simon_lfr, Thomas Skødt Andersen |
Expand Down
13 changes: 10 additions & 3 deletions packages/component/src/Localization/Localize.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Localize is designed to be elaboratively return multiple results and possibly exceeding complexity requirement
/* eslint complexity: "off" */

import connectToWebChat from '../connectToWebChat';
midineo marked this conversation as resolved.
Show resolved Hide resolved
midineo marked this conversation as resolved.
Show resolved Hide resolved
import getLocaleString from './getLocaleString';
import useLocalize from '../hooks/useLocalize';

import arEG from './ar-EG';
import bgBG from './bg-BG';
import csCZ from './cs-CZ';
import daDK from './da-DK';
Expand Down Expand Up @@ -33,7 +34,9 @@ import zhYUE from './zh-YUE';
function normalizeLanguage(language) {
language = language.toLowerCase();

if (language.startsWith('bg')) {
if (language.startsWith('ar')) {
return 'ar-EG';
} else if (language.startsWith('bg')) {
return 'bg-BG';
} else if (language.startsWith('cs')) {
return 'cs-CZ';
Expand Down Expand Up @@ -88,6 +91,8 @@ function normalizeLanguage(language) {

function getStrings(language) {
switch (normalizeLanguage(language || '')) {
case 'ar-EG':
return arEG;
case 'bg-BG':
return bgBG;
case 'cs-CZ':
Expand Down Expand Up @@ -152,6 +157,8 @@ function localize(text, language, ...args) {
return string || text;
}

export default ({ args, text }) => useLocalize(text, ...(args || []));
export default connectToWebChat(({ language }) => ({ language }))(({ args, language, text }) =>
midineo marked this conversation as resolved.
Show resolved Hide resolved
localize(text, language, ...(args || []))
midineo marked this conversation as resolved.
Show resolved Hide resolved
);
midineo marked this conversation as resolved.
Show resolved Hide resolved

export { getLocaleString, localize };
103 changes: 103 additions & 0 deletions packages/component/src/Localization/ar-EG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/* 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);
const countofMinutesIsTen = 10; /* used for arabic translation only */

if (deltaInMinutes < 1) {
return 'حالا';
} else if (deltaInMinutes === 1) {
return 'منذ دقيقة';
} else if ((deltaInHours < 1) & (deltaInMinutes <= countofMinutesIsTen)) {
return `منذ ${deltaInMinutes} دقائق`;
} else if (deltaInHours < 1) {
return `منذ ${deltaInMinutes} دقيقة`;
} else if (deltaInHours === 1) {
return `منذ ساعة`;
} else if (deltaInHours < 5) {
return `منذ ${deltaInHours} ساعات`;
} else if (deltaInHours <= 24) {
return `اليوم`;
} else if (deltaInHours <= 48) {
return `أمس`;
}
return getLocaleString(date, 'ar-EG');
}

function botSaidSomething(avatarInitials, text) {
// return `Bot ${avatarInitials} said, ${text}`;
return `البوت ${avatarInitials} قال, ${text}`;
}

function downloadFileWithFileSize(downloadFileText, fileName, size) {
// Full text should read: "Download file <filename> of size <filesize>"
// return `${downloadFileText} ${fileName} of size ${size}`;
return `تحميل ملف ${fileName} بحجم ${size}`;
midineo marked this conversation as resolved.
Show resolved Hide resolved
}

function uploadFileWithFileSize(fileName, size) {
midineo marked this conversation as resolved.
Show resolved Hide resolved
// return `${fileName} of size ${size}`;
midineo marked this conversation as resolved.
Show resolved Hide resolved
return `${fileName} بحجم ${size}`;
}

function userSaidSomething(avatarInitials, text) {
// return `User ${avatarInitials} said, ${text}`;
return `المستخدم ${avatarInitials} قال, ${text}`;
}

export default {
CONNECTED_NOTIFICATION: 'متصل',
FAILED_CONNECTION_NOTIFICATION: 'غير قادر على الاتصال.',
INITIAL_CONNECTION_NOTIFICATION: 'يتم التوصيل...',
midineo marked this conversation as resolved.
Show resolved Hide resolved
INTERRUPTED_CONNECTION_NOTIFICATION: 'حدث انقطاع في الشبكة. إعادة التوصيل ...',
midineo marked this conversation as resolved.
Show resolved Hide resolved
RENDER_ERROR_NOTIFICATION: 'خطأ في التقديم. يرجى التحقق من وحدة التحكم أو الاتصال بمطور البوت.',
// 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…': 'يستمع ...',
midineo marked this conversation as resolved.
Show resolved Hide resolved
'New messages': 'رسائل جديدة',
Retry: 'إعادة المحاولة',
Right: 'يمين',
Send: 'أرسل',
SendBox: 'Sendbox',
Sending: 'أرسال',
SendStatus: 'ارسل الحالة: ',
SentAt: 'أرسل: ',
Speak: 'تكلم',
'Starting…': 'يبدأ...',
midineo marked this conversation as resolved.
Show resolved Hide resolved
Tax: 'ضريبة',
Total: 'المجموع',
'Type your message': 'اكتب رسالتك',
TypingIndicator: 'عرض مؤشر الكتابة',
'Upload file': 'رفع الملف',
UploadFileWithFileSize: uploadFileWithFileSize,
UserSent: 'المستخدم أرسل: ',
VAT: 'ضريبة القيمة المضافة'
};
1 change: 1 addition & 0 deletions packages/embed/src/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -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-EG',
bg: 'bg-BG',
cs: 'cs-CZ',
de: 'de-DE',
Expand Down
4 changes: 4 additions & 0 deletions packages/embed/src/locale.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { normalize, toAzureLocale } from './locale';

test('Normalizing "ar.ar-eg"', () => {
expect(normalize('ar.ar-eg')).toBe('ar-EG');
});

test('Normalizing "en.en-us"', () => {
expect(normalize('en.en-us')).toBe('en-US');
});
Expand Down
1 change: 1 addition & 0 deletions packages/playground/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ const App = ({ store }) => {
Language
<select onChange={handleLanguageChange} value={language}>
<option value="">Default ({window.navigator.language})</option>
<option value="ar-EG">Arabic</option>
<option value="bg-BG">Bulgarian</option>
<option value="zh-HK">Chinese (Hong Kong)</option>
<option value="zh-YUE">Chinese (Hong Kong, Yue)</option>
Expand Down