Skip to content

Modify locale cache to support country variants. #1359

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

Merged
merged 1 commit into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ public Map<String, Object> getControllerAdviceMap() {
* @return the cached open api
*/
public OpenAPI getCachedOpenAPI(Locale locale) {
return cachedOpenAPI.get(locale.getLanguage());
return cachedOpenAPI.get(locale.toLanguageTag());
}

/**
Expand All @@ -739,7 +739,7 @@ public OpenAPI getCachedOpenAPI(Locale locale) {
* @param cachedOpenAPI the cached open api
*/
public void setCachedOpenAPI(OpenAPI cachedOpenAPI, Locale locale) {
this.cachedOpenAPI.put(locale.getLanguage(), cachedOpenAPI);
this.cachedOpenAPI.put(locale.toLanguageTag(), cachedOpenAPI);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void testApp() throws Exception {
Locale.setDefault(Locale.US);
testApp(Locale.US);
testApp(Locale.FRANCE);
testApp(Locale.UK);
}

private void testApp(Locale locale) throws Exception {
Expand All @@ -57,7 +58,7 @@ private void testApp(Locale locale) throws Exception {
mockMvc.perform(get(Constants.DEFAULT_API_DOCS_URL).locale(locale).header(HttpHeaders.ACCEPT_LANGUAGE, locale.toLanguageTag())).andExpect(status().isOk())
.andExpect(jsonPath("$.openapi", is("3.0.1"))).andReturn();
String result = mockMvcResult.getResponse().getContentAsString();
String expected = getContent("results/app" + testNumber + "-" + locale.getLanguage() + ".json");
String expected = getContent("results/app" + testNumber + "-" + locale.toLanguageTag() + ".json");
assertEquals(expected, result, true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
greeting=Hello! Welcome to our website![EN_GB]
lang.change=Change the language[EN_GB]
lang.eng=English[EN_GB]
lang.fr=French[EN_GB]
mySample=toto[EN_GB]
test=This is a test message[EN_GB]
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localhost",
"description": "Generated server url"
}
],
"tags": [
{
"name": "Hello! Welcome to our website![EN_GB]",
"description": "This is a test message[EN_GB]"
}
],
"paths": {
"/test": {
"get": {
"tags": [
"Hello! Welcome to our website![EN_GB]"
],
"operationId": "demo2",
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/persons": {
"get": {
"tags": [
"Hello! Welcome to our website![EN_GB]"
],
"operationId": "persons",
"parameters": [
{
"name": "name",
"in": "query",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
}
},
"components": {}
}