-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(street-service): add low level request optimization for multi la…
…nguage search
- Loading branch information
1 parent
5cf1415
commit f1a120b
Showing
3 changed files
with
160 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Service, { inject as service } from "@ember/service"; | ||
import { languageOptions } from "ember-ebau-gwr/models/options"; | ||
|
||
export default class LanguagesService extends Service { | ||
@service config; | ||
|
||
languages = { | ||
AG: ["de"], | ||
AR: ["de"], | ||
AI: ["de"], | ||
BL: ["de"], | ||
BS: ["de"], | ||
BE: ["de", "fr"], | ||
FR: ["de", "fr"], | ||
GE: ["de", "fr"], | ||
GL: ["de"], | ||
GR: ["de", "rm", "it"], | ||
JU: ["fr"], | ||
LU: ["de"], | ||
NE: ["fr"], | ||
NW: ["de"], | ||
OW: ["de"], | ||
SH: ["de"], | ||
SZ: ["de"], | ||
SO: ["de"], | ||
SG: ["de"], | ||
TI: ["it"], | ||
TG: ["de"], | ||
UR: ["de"], | ||
VD: ["fr"], | ||
VS: ["de", "fr"], | ||
ZG: ["de"], | ||
ZH: ["de"], | ||
}; | ||
|
||
get availableLanguages() { | ||
return this.config.cantonAbbreviation | ||
? this.languages[this.config.cantonAbbreviation] | ||
: ["de", "rm", "fr", "it"]; | ||
} | ||
|
||
codeToLanguage(code) { | ||
return Object.entries(languageOptions).find( | ||
([, value]) => value === code, | ||
)[0]; | ||
} | ||
|
||
languageToCode(languageAbbreviation) { | ||
return languageOptions[languageAbbreviation]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { setupTest } from "dummy/tests/helpers"; | ||
import { module, test } from "qunit"; | ||
|
||
module("Unit | Service | languages", function (hooks) { | ||
setupTest(hooks); | ||
|
||
test("available languages for a given canton", function (assert) { | ||
const configService = this.owner.lookup("service:config"); | ||
const languagesService = this.owner.lookup("service:languages"); | ||
|
||
configService.cantonAbbreviation = "GR"; | ||
|
||
assert.deepEqual(languagesService.availableLanguages, ["de", "rm", "it"]); | ||
|
||
configService.cantonAbbreviation = "BE"; | ||
|
||
assert.deepEqual(languagesService.availableLanguages, ["de", "fr"]); | ||
}); | ||
|
||
test("transforms language abbrevation to gwr API language code", function (assert) { | ||
const service = this.owner.lookup("service:languages"); | ||
|
||
assert.strictEqual(service.languageToCode("de"), 9901); | ||
assert.strictEqual(service.languageToCode("rm"), 9902); | ||
assert.strictEqual(service.languageToCode("fr"), 9903); | ||
assert.strictEqual(service.languageToCode("it"), 9904); | ||
}); | ||
|
||
test("transforms gwr API language code to language abbrevation", function (assert) { | ||
const service = this.owner.lookup("service:languages"); | ||
|
||
assert.strictEqual(service.codeToLanguage(9901), "de"); | ||
assert.strictEqual(service.codeToLanguage(9902), "rm"); | ||
assert.strictEqual(service.codeToLanguage(9903), "fr"); | ||
assert.strictEqual(service.codeToLanguage(9904), "it"); | ||
}); | ||
}); |