Skip to content

Commit

Permalink
fixes for language overrides #997 (#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgershman authored Apr 13, 2024
1 parent f5a45cd commit d5eba4e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 21 deletions.
24 changes: 19 additions & 5 deletions src/app/Services/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
}
}
}
1 change: 1 addition & 0 deletions src/config.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
6 changes: 2 additions & 4 deletions src/docs/docs/general/language-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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:
Expand Down Expand Up @@ -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/).
2 changes: 1 addition & 1 deletion src/docs/docs/general/voice-recognition-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 28 additions & 9 deletions src/tests/Feature/InputMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
'<?xml version="1.0" encoding="UTF-8"?>',
'<Response>',
'<Gather language="en-US" input="dtmf" numDigits="1" timeout="10" speechTimeout="auto" action="input-method-result.php?SearchType=1" method="GET">',
'<Say voice="alice" language="en-US">press one to search for someone to talk to by city or county</Say>',
'<Say voice="alice" language="en-US">press one to search for someone to talk to by city or suburb</Say>',
'<Say voice="alice" language="en-US">press two to search for someone to talk to by zip code</Say>',
'</Gather>',
'</Response>'
], 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"
]);
Expand All @@ -49,7 +49,26 @@
'<?xml version="1.0" encoding="UTF-8"?>',
'<Response>',
'<Gather language="en-US" input="dtmf" numDigits="1" timeout="10" speechTimeout="auto" action="input-method-result.php?SearchType=1" method="GET">',
'<Say voice="alice" language="en-US">press one to search for someone to talk to by city or suburb</Say>',
'<Say voice="alice" language="en-US">press one to search for someone to talk to by foo or bar</Say>',
'<Say voice="alice" language="en-US">press two to search for someone to talk to by zip code</Say>',
'</Gather>',
'</Response>'
], 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([
'<?xml version="1.0" encoding="UTF-8"?>',
'<Response>',
'<Gather language="en-US" input="dtmf" numDigits="1" timeout="10" speechTimeout="auto" action="input-method-result.php?SearchType=1" method="GET">',
'<Say voice="alice" language="en-US">press one to search for someone to talk to by bar or foo</Say>',
'<Say voice="alice" language="en-US">press two to search for someone to talk to by zip code</Say>',
'</Gather>',
'</Response>'
Expand Down Expand Up @@ -80,7 +99,7 @@
'<Response>',
'<Say voice="alice" language="en-US">Meeting search results will also be sent to you by SMS text message.</Say>',
'<Gather language="en-US" input="dtmf" numDigits="1" timeout="10" speechTimeout="auto" action="input-method-result.php?SearchType=2" method="GET">',
'<Say voice="alice" language="en-US">press one to search for meetings by city or county</Say>',
'<Say voice="alice" language="en-US">press one to search for meetings by city or suburb</Say>',
'<Say voice="alice" language="en-US">press two to search for meetings by zip code</Say>',
'</Gather>',
'</Response>'
Expand Down Expand Up @@ -232,7 +251,7 @@
'<Response>',
'<Say voice="alice" language="en-US">Meeting search results will also be sent to you by SMS text message.</Say>',
'<Gather language="en-US" input="dtmf" numDigits="1" timeout="10" speechTimeout="auto" action="input-method-result.php?SearchType=2" method="GET">',
'<Say voice="alice" language="en-US">press one to search for meetings by city or county</Say>',
'<Say voice="alice" language="en-US">press one to search for meetings by city or suburb</Say>',
'<Say voice="alice" language="en-US">press two to search for meetings by zip code</Say>',
'<Say voice="alice" language="en-US">press three to listen to the just for today</Say>',
'<Say voice="alice" language="en-US">press four to listen to the spiritual principle a day</Say>',
Expand Down Expand Up @@ -280,7 +299,7 @@
'<Say voice="alice" language="en-US">Meeting search results will also be sent to you by SMS text message.</Say>',
'<Gather language="en-US" input="dtmf" numDigits="1" timeout="10" speechTimeout="auto" action="input-method-result.php?SearchType=2" method="GET">',
'<Say voice="alice" language="en-US">Test Helpline</Say>',
'<Say voice="alice" language="en-US">press one to search for meetings by city or county</Say>',
'<Say voice="alice" language="en-US">press one to search for meetings by city or suburb</Say>',
'<Say voice="alice" language="en-US">press two to search for meetings by zip code</Say>',
'</Gather>',
'</Response>'
Expand Down Expand Up @@ -318,7 +337,7 @@
'<Gather language="en-US" input="dtmf" numDigits="1" timeout="10" speechTimeout="auto" action="input-method-result.php?SearchType=1" method="GET">',
'<Say voice="alice" language="en-US">You Failed Son!</Say>',
'<Pause length="1"/>',
'<Say voice="alice" language="en-US">press one to search for someone to talk to by city or county</Say>',
'<Say voice="alice" language="en-US">press one to search for someone to talk to by city or suburb</Say>',
'<Say voice="alice" language="en-US">press two to search for someone to talk to by zip code</Say>',
'</Gather>',
'</Response>'
Expand All @@ -339,7 +358,7 @@
'<Gather language="en-US" input="dtmf" numDigits="1" timeout="10" speechTimeout="auto" action="input-method-result.php?SearchType=1" method="GET">',
'<Say voice="alice" language="en-US">sorry, could not find location, please retry your entry</Say>',
'<Pause length="1"/>',
'<Say voice="alice" language="en-US">press one to search for someone to talk to by city or county</Say>',
'<Say voice="alice" language="en-US">press one to search for someone to talk to by city or suburb</Say>',
'<Say voice="alice" language="en-US">press two to search for someone to talk to by zip code</Say>',
'</Gather>',
'</Response>'
Expand Down
4 changes: 2 additions & 2 deletions src/tests/Feature/InputsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
'<Response>',
'<Gather language="en-US" input="speech" hints="" timeout="10" speechTimeout="auto" action="voice-input-result.php?SearchType=1&amp;Province=" method="GET">',
'<Say voice="alice" language="en-US">',
'please say the name of the city or county',
'please say the name of the city or suburb',
'</Say>',
'</Gather>',
'</Response>'
Expand All @@ -131,7 +131,7 @@
'<Response>',
'<Gather language="en-US" input="speech" hints="Raleigh,Lillington,Benson,Dunn" timeout="10" speechTimeout="auto" action="voice-input-result.php?SearchType=1&amp;Province=" method="GET">',
'<Say voice="alice" language="en-US">',
'please say the name of the city or county',
'please say the name of the city or suburb',
'</Say>',
'</Gather>',
'</Response>'
Expand Down

0 comments on commit d5eba4e

Please sign in to comment.