From d5eba4e2c3c3af42cd5d72012ccdedef34a85f65 Mon Sep 17 00:00:00 2001 From: Danny Gershman Date: Fri, 12 Apr 2024 21:55:48 -0400 Subject: [PATCH] fixes for language overrides #997 (#1015) --- src/app/Services/SettingsService.php | 24 +++++++++--- src/config.test.php | 1 + src/docs/docs/general/language-options.md | 6 +-- .../docs/general/voice-recognition-options.md | 2 +- src/tests/Feature/InputMethodTest.php | 37 ++++++++++++++----- src/tests/Feature/InputsTest.php | 4 +- 6 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/app/Services/SettingsService.php b/src/app/Services/SettingsService.php index ec6559561..8835ab2a0 100644 --- a/src/app/Services/SettingsService.php +++ b/src/app/Services/SettingsService.php @@ -145,12 +145,12 @@ public function __construct() $this->shortLanguage = $this->getWordLanguage() === "da-DK" ? "dk" : explode("-", $this->getWordLanguage())[0]; + foreach ($this->settings as $setting_key => $setting_value) { + $this->setLocalizationOverride($setting_key, $setting_value); + } + foreach ($_SESSION ?? [] as $session_key => $session_value) { - $language = $this->getWordLanguage(); - $stripped_key_test = str_replace("override_", "", $session_key); - if (isset($this->localizations->getLocalization($language)[$stripped_key_test])) { - $this->localizations->getLocalization($language)[$session_key] = $session_value; - } + $this->setLocalizationOverride($session_key, $session_value); } } @@ -426,4 +426,18 @@ public function getCurrentTime(): string { return gmdate("Y-m-d H:i:s"); } + + /** + * @param int|string $session_key + * @param mixed $session_value + * @return void + */ + public function setLocalizationOverride(int|string $session_key, mixed $session_value): void + { + $language = $this->getWordLanguage(); + $stripped_key_test = str_replace("override_", "", $session_key); + if (isset($this->localizations->getLocalization($language)[$stripped_key_test])) { + $this->localizations->getLocalization($language)[$session_key] = $session_value; + } + } } diff --git a/src/config.test.php b/src/config.test.php index aa8942752..a913b7f2f 100644 --- a/src/config.test.php +++ b/src/config.test.php @@ -9,3 +9,4 @@ #https://www.twilio.com/docs/iam/test-credentials static $twilio_account_sid = "AC222a79bf52fdc8c3cf463b2846582b83"; static $twilio_auth_token = "92433fddb38394db9bb63c5cee66b5d9"; +static $override_city_or_county = "city or suburb"; diff --git a/src/docs/docs/general/language-options.md b/src/docs/docs/general/language-options.md index 502430ed0..ef8cf83b6 100644 --- a/src/docs/docs/general/language-options.md +++ b/src/docs/docs/general/language-options.md @@ -2,7 +2,7 @@ --- -There is a concept of language resource files. You will notice them in the `lang/` folder. Please open a ticket if you would like to contribute to translating to another language. +There is a concept of language resource files. You will notice them in the `app/Models/Localizations.php` file. Please open a ticket if you would like to contribute to translating to another language. You can also override any of the language prompts in the `config.php` file. @@ -12,8 +12,6 @@ For example, say you wanted to still use English, but change the "city or county static $override_city_or_county = "city or suburb"; ``` -You can see the full listing in the `lang/en-US.php` which always has the full latest listing of the voice prompts. - You can also change the spoken language accent. There is a wide variety. See the Twilio documentation for more details: [https://www.twilio.com/docs/voice/twiml/say#attributes-language](https://www.twilio.com/docs/voice/twiml/say#attributes-language). There are also some additional voices available here as well [https://www.twilio.com/docs/voice/twiml/say/text-speech#voices](https://www.twilio.com/docs/voice/twiml/say/text-speech#voices). An example would be using an Australian English Accent. Set your config.php to: @@ -43,4 +41,4 @@ Voices can be configured for every language option. For example for Spanish: es_US_voice = "Polly.Penelope"; ``` -**New Yap 3.0** If you want to route calls to volunteers by language, see the section on Language in [Specialized Routing](../../helpline/specialized-routing/). +If you want to route calls to volunteers by language, see the section on Language in [Specialized Routing](../../helpline/specialized-routing/). diff --git a/src/docs/docs/general/voice-recognition-options.md b/src/docs/docs/general/voice-recognition-options.md index 94fceea77..719bc4586 100644 --- a/src/docs/docs/general/voice-recognition-options.md +++ b/src/docs/docs/general/voice-recognition-options.md @@ -17,7 +17,7 @@ Each hint may not be more than 100 characters (including spaces). You can use u static $gather_hints = ""; ``` -**New Yap 3.x** Voice recognition for input gathering is turned on by default, to turn it off you can do the following. +Voice recognition for input gathering is turned on by default, to turn it off you can do the following. ```php static $speech_gathering = false; diff --git a/src/tests/Feature/InputMethodTest.php b/src/tests/Feature/InputMethodTest.php index 29b162bac..2624bb3f9 100644 --- a/src/tests/Feature/InputMethodTest.php +++ b/src/tests/Feature/InputMethodTest.php @@ -30,15 +30,15 @@ '', '', '', - 'press one to search for someone to talk to by city or county', + 'press one to search for someone to talk to by city or suburb', 'press two to search for someone to talk to by zip code', '', '' ], false); })->with(['GET', 'POST']); -test('search for volunteers with word overrides', function ($method) { - $_SESSION['override_city_or_county'] = "city or suburb"; +test('search for volunteers with word overrides with session', function ($method) { + $_SESSION['override_city_or_county'] = "foo or bar"; $response = $this->call($method, '/input-method.php', [ "Digits"=>"1" ]); @@ -49,7 +49,26 @@ '', '', '', - 'press one to search for someone to talk to by city or suburb', + 'press one to search for someone to talk to by foo or bar', + 'press two to search for someone to talk to by zip code', + '', + '' + ], false); +})->with(['GET', 'POST']); + +test('search for volunteers with word overrides with querystring', function ($method) { + $response = $this->call($method, '/input-method.php', [ + "Digits"=>"1", + "override_city_or_county" => "bar or foo" + ]); + $response + ->assertStatus(200) + ->assertHeader("Content-Type", "text/xml; charset=UTF-8") + ->assertSeeInOrderExact([ + '', + '', + '', + 'press one to search for someone to talk to by bar or foo', 'press two to search for someone to talk to by zip code', '', '' @@ -80,7 +99,7 @@ '', 'Meeting search results will also be sent to you by SMS text message.', '', - 'press one to search for meetings by city or county', + 'press one to search for meetings by city or suburb', 'press two to search for meetings by zip code', '', '' @@ -232,7 +251,7 @@ '', 'Meeting search results will also be sent to you by SMS text message.', '', - 'press one to search for meetings by city or county', + 'press one to search for meetings by city or suburb', 'press two to search for meetings by zip code', 'press three to listen to the just for today', 'press four to listen to the spiritual principle a day', @@ -280,7 +299,7 @@ 'Meeting search results will also be sent to you by SMS text message.', '', 'Test Helpline', - 'press one to search for meetings by city or county', + 'press one to search for meetings by city or suburb', 'press two to search for meetings by zip code', '', '' @@ -318,7 +337,7 @@ '', 'You Failed Son!', '', - 'press one to search for someone to talk to by city or county', + 'press one to search for someone to talk to by city or suburb', 'press two to search for someone to talk to by zip code', '', '' @@ -339,7 +358,7 @@ '', 'sorry, could not find location, please retry your entry', '', - 'press one to search for someone to talk to by city or county', + 'press one to search for someone to talk to by city or suburb', 'press two to search for someone to talk to by zip code', '', '' diff --git a/src/tests/Feature/InputsTest.php b/src/tests/Feature/InputsTest.php index 457a81a96..ee0416652 100644 --- a/src/tests/Feature/InputsTest.php +++ b/src/tests/Feature/InputsTest.php @@ -112,7 +112,7 @@ '', '', '', - 'please say the name of the city or county', + 'please say the name of the city or suburb', '', '', '' @@ -131,7 +131,7 @@ '', '', '', - 'please say the name of the city or county', + 'please say the name of the city or suburb', '', '', ''