From 66ded1e739e8e5cda8629671d92b26f44855f0a8 Mon Sep 17 00:00:00 2001 From: Duncan Walker Date: Thu, 18 May 2017 08:56:28 +0100 Subject: [PATCH 1/6] Fix localisation - locale files were not picked up once built --- .travis.yml | 2 +- features/i18n-commands.feature | 4 ++++ server/helpers/translator.js | 4 ++-- server/routing/command-router.js | 4 +++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index d79d2be..dcca219 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ services: - mongodb env: - MONGODBURI=localhost:27017/smsup - SUPPORTED_LOCALES=en,fa + SUPPORTED_LOCALES=en,fa,so ACTIVE_GATEWAY=nexmo MEXCOM_PREMIUM_KEYWORDS=APPS10 ADMIN_AUTH_SECRET=catkeyboard diff --git a/features/i18n-commands.feature b/features/i18n-commands.feature index 78d7962..8e35e28 100644 --- a/features/i18n-commands.feature +++ b/features/i18n-commands.feature @@ -2,6 +2,10 @@ Feature: Internationalisation As a user I can interact with SMS in my right-to-left language + Scenario: Command in Somali language + When I send an SMS to SMSUP with content 'abuuris somaligroup' + Then I receive an SMS with the content ''somaligroup' group created. ' + Scenario: Command in local language Given that the 'رهبران' group exists When I send an SMS to SMSUP with content 'ورود رهبران' diff --git a/server/helpers/translator.js b/server/helpers/translator.js index 0ed0ee2..d16e59c 100644 --- a/server/helpers/translator.js +++ b/server/helpers/translator.js @@ -1,10 +1,10 @@ const i18n = require('i18n'); -const path = require('path'); i18n.configure({ locales: ['en', 'fa'], defaultLocale: 'en', - directory: path.resolve(__dirname, './../locales'), + // eslint-disable-next-line prefer-template,no-path-concat + directory: __dirname + '/../locales', syncFiles: !(process.env.NODE_ENV === 'production'), }); diff --git a/server/routing/command-router.js b/server/routing/command-router.js index 6ca027d..2531519 100644 --- a/server/routing/command-router.js +++ b/server/routing/command-router.js @@ -87,7 +87,9 @@ function create() { const language = findLanguage(mo.text, match.route.pattern); const options = { language }; - return match.route.action({ params: match.params, language }, mo) + const params = { params: match.params, language }; + winston.log('Routing', params, mo); + return match.route.action(params, mo) .then(viewModel => viewRender(match.route.view, viewModel, options)) .catch(error => errorHandler(error, options)) .then((viewModel) => { From 923728747420ae7815cc33df645743860dddd8f5 Mon Sep 17 00:00:00 2001 From: abdulrazaqatayee Date: Thu, 18 May 2017 17:09:35 +0800 Subject: [PATCH 2/6] Update fa.json The change completed, with Farsi version. --- server/locales/fa.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/locales/fa.json b/server/locales/fa.json index c2bdc63..5291c5c 100644 --- a/server/locales/fa.json +++ b/server/locales/fa.json @@ -1,10 +1,10 @@ { - "create": "ساختن", - "delete": "حذف كردن", + "create": "ایجاد", + "delete": "حذف", "'{{groupName}}' group created.": "'{{groupName}}' group created.", - "invite": "invite", - "join": "ورود", - "leave": "خارج", + "invite": "دعوت", + "join": "عضویت", + "leave": "خروج", "Reply \"{{prefix}}join {{groupName}}\" to join.": "Reply \"join {{groupName}}\" to join.", "SMS Up terms of use are.": "«با ثبت نام در SMSUP، موافقت می کنید تا از ارسال هرگونه پیام شرم آور، تهدیدآمیز، و مخالف قانون جاری و نافذ خودداری می کنید. بدین وسیله UR را از پرداخت غرامت در قبال هرگونه آسیب، مسئولیت، صدمه، یا هر هزینه ای که در نتیجه استفاده شما از SMSUP منتج شود، مبرا می کنید", "the {{groupName}} group has been deleted.": "the {{groupName}} group has been deleted.", @@ -15,4 +15,4 @@ "That didn't work, try again": "That didn't work, try again", "Sorry but the '{{groupName}}' group doesn't exist": "Sorry but the '{{groupName}}' group doesn't exist", "Sorry, you send a message to '{{groupName}}' but no group with name exists. Start your message with name of a group": "Sorry, you send a message to '{{groupName}}' but no group with name exists. Start your message with name of a group" -} \ No newline at end of file +} From 67454cc84bc75d5f5d5c38147b0b6a81c9ef06f0 Mon Sep 17 00:00:00 2001 From: Duncan Walker Date: Thu, 18 May 2017 08:56:28 +0100 Subject: [PATCH 3/6] Fix localisation - locale files were not picked up once built --- .travis.yml | 2 +- features/i18n-commands.feature | 4 ++++ server/helpers/translator.js | 6 ++++-- server/routing/command-router.js | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index d79d2be..dcca219 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ services: - mongodb env: - MONGODBURI=localhost:27017/smsup - SUPPORTED_LOCALES=en,fa + SUPPORTED_LOCALES=en,fa,so ACTIVE_GATEWAY=nexmo MEXCOM_PREMIUM_KEYWORDS=APPS10 ADMIN_AUTH_SECRET=catkeyboard diff --git a/features/i18n-commands.feature b/features/i18n-commands.feature index 78d7962..8e35e28 100644 --- a/features/i18n-commands.feature +++ b/features/i18n-commands.feature @@ -2,6 +2,10 @@ Feature: Internationalisation As a user I can interact with SMS in my right-to-left language + Scenario: Command in Somali language + When I send an SMS to SMSUP with content 'abuuris somaligroup' + Then I receive an SMS with the content ''somaligroup' group created. ' + Scenario: Command in local language Given that the 'رهبران' group exists When I send an SMS to SMSUP with content 'ورود رهبران' diff --git a/server/helpers/translator.js b/server/helpers/translator.js index 0ed0ee2..f03b3b9 100644 --- a/server/helpers/translator.js +++ b/server/helpers/translator.js @@ -1,10 +1,12 @@ const i18n = require('i18n'); const path = require('path'); +// TODO: sort out including locale files in build +const locales = process.env.NODE_ENV === 'production' ? './../server/locales' : './../locales'; i18n.configure({ - locales: ['en', 'fa'], + locales: (process.env.SUPPORTED_LOCALES || 'en').split(','), defaultLocale: 'en', - directory: path.resolve(__dirname, './../locales'), + directory: path.resolve(__dirname, locales), syncFiles: !(process.env.NODE_ENV === 'production'), }); diff --git a/server/routing/command-router.js b/server/routing/command-router.js index 6ca027d..2531519 100644 --- a/server/routing/command-router.js +++ b/server/routing/command-router.js @@ -87,7 +87,9 @@ function create() { const language = findLanguage(mo.text, match.route.pattern); const options = { language }; - return match.route.action({ params: match.params, language }, mo) + const params = { params: match.params, language }; + winston.log('Routing', params, mo); + return match.route.action(params, mo) .then(viewModel => viewRender(match.route.view, viewModel, options)) .catch(error => errorHandler(error, options)) .then((viewModel) => { From 53969228684bec5563c822241e6e576ad45ae940 Mon Sep 17 00:00:00 2001 From: Duncan Walker Date: Sun, 21 May 2017 19:00:45 +0100 Subject: [PATCH 4/6] Add rejoin instructions to leave autoreply --- server/views/auto-replies.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/views/auto-replies.js b/server/views/auto-replies.js index e373888..3770caa 100644 --- a/server/views/auto-replies.js +++ b/server/views/auto-replies.js @@ -3,7 +3,10 @@ const autoReplies = { __('You have joined the {{groupName}} group.', viewModel), viewModel.includeTerms ? __('SMS Up terms of use are.', viewModel) : '', ]), - leave: (viewModel, { __ }) => __('You have left the {{groupName}} group.', viewModel), + leave: (viewModel, { __, join }) => join([ + __('You have left the {{groupName}} group.', viewModel), + __('Reply "join {{groupName}}" to rejoin', viewModel), + ]), create: (viewModel, { __ }) => __('\'{{groupName}}\' group created. ', viewModel), delete: (viewModel, { __ }) => __('the {{groupName}} group has been deleted.', viewModel), invitation: (viewModel, { __, join }) => join([ From e4878532439a59432e74c6f4174d70301a135ee0 Mon Sep 17 00:00:00 2001 From: Duncan Walker Date: Sun, 21 May 2017 19:08:43 +0100 Subject: [PATCH 5/6] Add placeholder lines to translation files --- server/locales/en.json | 6 +++--- server/locales/fa.json | 4 +++- server/locales/so.json | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/server/locales/en.json b/server/locales/en.json index a1e5823..a02aeab 100644 --- a/server/locales/en.json +++ b/server/locales/en.json @@ -1,14 +1,13 @@ { "create": "create", "delete": "delete", - "'{{groupName}}' group created.": "'{{groupName}}' group created.", + "'{{groupName}}' group created.": "'{{groupName}}' group created.", "invite": "invite", "join": "join", "leave": "leave", "Reply \"{{prefix}}join {{groupName}}\" to join.": "Reply \"join {{groupName}}\" to join.", "SMS Up terms of use are.": "SMS Up terms of use are.", - "the {{groupName}} group has been deleted.": "the {{groupName}} group has been deleted.", - "to": "to", + "the {{groupName}} group has been deleted.": "the {{groupName}} group has been deleted.", "You have been invited to the '{{groupName}}' group.": "You have been invited to the '{{groupName}}' group.", "You have joined the {{groupName}} group.": "You have joined the {{groupName}} group.", "You have left the {{groupName}} group.": "You have left the {{groupName}} group.", @@ -16,4 +15,5 @@ "That didn't work, try again": "That didn't work, try again", "Sorry but the '{{groupName}}' group doesn't exist": "Sorry but the '{{groupName}}' group doesn't exist", "Sorry, you send a message to '{{groupName}}' but no group with name exists. Start your message with name of a group": "Sorry, you send a message to '{{groupName}}' but no group with name exists. Start your message with name of a group" + "Reply 'join {{groupName}}' to rejoin": "Reply 'join {{groupName}}'\"' to rejoin" } \ No newline at end of file diff --git a/server/locales/fa.json b/server/locales/fa.json index c2bdc63..bb1df2d 100644 --- a/server/locales/fa.json +++ b/server/locales/fa.json @@ -14,5 +14,7 @@ "You have left the {{groupName}} group.": "شما از گروهي به نام {{groupName}} خارج شده ايد.", "That didn't work, try again": "That didn't work, try again", "Sorry but the '{{groupName}}' group doesn't exist": "Sorry but the '{{groupName}}' group doesn't exist", - "Sorry, you send a message to '{{groupName}}' but no group with name exists. Start your message with name of a group": "Sorry, you send a message to '{{groupName}}' but no group with name exists. Start your message with name of a group" + "Sorry, you send a message to '{{groupName}}' but no group with name exists. Start your message with name of a group": "Sorry, you send a message to '{{groupName}}' but no group with name exists. Start your message with name of a group", + "'{{groupName}}' group created. ": "'{{groupName}}' group created. ", + "Reply 'join {{groupName}}'\"' to rejoin": "Reply 'join {{groupName}}' to rejoin" } \ No newline at end of file diff --git a/server/locales/so.json b/server/locales/so.json index b394249..b9b2531 100644 --- a/server/locales/so.json +++ b/server/locales/so.json @@ -11,5 +11,7 @@ "to": "to", "You have been invited to the '{{groupName}}' group.": "Waxaa laguugu casuumay kooxda magaceedu yahay {{groupName}}.", "You have joined the {{groupName}} group.": "Waxaad ku soo biirtay kooxda magaceedu yahay {{groupName}}. SMS Up habka loo isticmaalo waa...", - "You have left the {{groupName}} group.": "You have left the {{groupName}} group." + "You have left the {{groupName}} group.": "You have left the {{groupName}} group.", + "'{{groupName}}' group created. ": "'{{groupName}}' group created. ", + "Reply 'join {{groupName}}' to rejoin": "Reply 'join {{groupName}}' to rejoin" } \ No newline at end of file From adc46297cbe5173c4a1f672825fd3122f2cb473b Mon Sep 17 00:00:00 2001 From: Duncan Walker Date: Sun, 21 May 2017 19:09:17 +0100 Subject: [PATCH 6/6] Update command word farsi translations --- server/locales/fa.json | 10 +++++----- server/routing/__tests__/aliases.test.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/locales/fa.json b/server/locales/fa.json index bb1df2d..f1c6860 100644 --- a/server/locales/fa.json +++ b/server/locales/fa.json @@ -1,10 +1,10 @@ { - "create": "ساختن", - "delete": "حذف كردن", + "create": "ایجاد", + "delete": "حذف", "'{{groupName}}' group created.": "'{{groupName}}' group created.", - "invite": "invite", - "join": "ورود", - "leave": "خارج", + "invite": "دعوت", + "join": "عضویت", + "leave": "خروج", "Reply \"{{prefix}}join {{groupName}}\" to join.": "Reply \"join {{groupName}}\" to join.", "SMS Up terms of use are.": "«با ثبت نام در SMSUP، موافقت می کنید تا از ارسال هرگونه پیام شرم آور، تهدیدآمیز، و مخالف قانون جاری و نافذ خودداری می کنید. بدین وسیله UR را از پرداخت غرامت در قبال هرگونه آسیب، مسئولیت، صدمه، یا هر هزینه ای که در نتیجه استفاده شما از SMSUP منتج شود، مبرا می کنید", "the {{groupName}} group has been deleted.": "the {{groupName}} group has been deleted.", diff --git a/server/routing/__tests__/aliases.test.js b/server/routing/__tests__/aliases.test.js index 5826a03..d60807d 100644 --- a/server/routing/__tests__/aliases.test.js +++ b/server/routing/__tests__/aliases.test.js @@ -6,7 +6,7 @@ describe('Mobile originated message parsing', () => { }); it('', () => { expect(createAliases('leave')).toEqual( - [{ locale: 'fa', alias: 'خارج' }, { locale: 'en', alias: 'leave' }], + [{ locale: 'fa', alias: 'خروج' }, { locale: 'en', alias: 'leave' }], ); }); });