-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use quarkus compatible classloader
Use a classLoader that is compatible with quarkus for default i18N translation. part of vaadin/flow#18977
- Loading branch information
Showing
10 changed files
with
531 additions
and
126 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
...tests/common-test-code/src/main/java/com/vaadin/flow/quarkus/it/i18n/TranslationView.java
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,94 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.quarkus.it.i18n; | ||
|
||
import java.util.Locale; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import com.vaadin.flow.component.AttachEvent; | ||
import com.vaadin.flow.component.UI; | ||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.component.html.Span; | ||
import com.vaadin.flow.i18n.I18NProvider; | ||
import com.vaadin.flow.internal.LocaleUtil; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@Route(value = "translations") | ||
public class TranslationView extends Div { | ||
|
||
public static final String TEST_VIEW_ID = "TranslationView"; | ||
public static final String LOCALES_ID = "available-locales"; | ||
|
||
private Span dynamic; | ||
|
||
public TranslationView() { | ||
setId(TEST_VIEW_ID); | ||
|
||
Span defaultLang = new Span(getTranslation("label", Locale.ENGLISH)); | ||
defaultLang.setId("english"); | ||
Span german = new Span(getTranslation("label", Locale.GERMAN)); | ||
german.setId("german"); | ||
Span germany = new Span(getTranslation("label", Locale.GERMANY)); | ||
germany.setId("germany"); | ||
Span finnish = new Span( | ||
getTranslation("label", new Locale("fi", "FI"))); | ||
finnish.setId("finnish"); | ||
Span french = new Span(getTranslation("label", Locale.FRANCE)); | ||
french.setId("french"); | ||
Span japanese = new Span(getTranslation("label", Locale.JAPAN)); | ||
japanese.setId("japanese"); | ||
|
||
Optional<I18NProvider> i18NProvider = LocaleUtil.getI18NProvider(); | ||
if (i18NProvider.isPresent()) { | ||
add(new Span("Available translation locales:")); | ||
StringBuilder locales = new StringBuilder(); | ||
for (Locale locale : i18NProvider.get().getProvidedLocales()) { | ||
if (locales.length() > 0) { | ||
locales.append(", "); | ||
} | ||
locales.append(locale.toString()); | ||
} | ||
Span localeSpan = new Span(locales.toString()); | ||
localeSpan.setId(LOCALES_ID); | ||
add(localeSpan, new Div()); | ||
} | ||
dynamic = new Span("waiting"); | ||
dynamic.setId("dynamic"); | ||
|
||
add(defaultLang, new Div(), german, new Div(), germany, new Div(), | ||
finnish, new Div(), french, new Div(), japanese, new Div(), | ||
dynamic); | ||
} | ||
|
||
@Override | ||
protected void onAttach(AttachEvent event) { | ||
UI ui = event.getUI(); | ||
ui.setPollInterval(100); | ||
CompletableFuture.runAsync(() -> { | ||
try { | ||
Thread.sleep(50); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} finally { | ||
ui.access(() -> dynamic | ||
.setText(getTranslation("label", Locale.FRANCE))); | ||
ui.setPollInterval(-1); | ||
} | ||
}); | ||
|
||
} | ||
} |
1 change: 1 addition & 0 deletions
1
integration-tests/common-test-code/src/main/resources/vaadin-i18n/translations.properties
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 @@ | ||
label=Default |
1 change: 1 addition & 0 deletions
1
integration-tests/common-test-code/src/main/resources/vaadin-i18n/translations_de.properties
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 @@ | ||
label=Deutsch |
1 change: 1 addition & 0 deletions
1
...ation-tests/common-test-code/src/main/resources/vaadin-i18n/translations_fi_FI.properties
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 @@ | ||
label=Suomi |
1 change: 1 addition & 0 deletions
1
...ation-tests/common-test-code/src/main/resources/vaadin-i18n/translations_fr_FR.properties
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 @@ | ||
label=français |
1 change: 1 addition & 0 deletions
1
...ation-tests/common-test-code/src/main/resources/vaadin-i18n/translations_ja_JP.properties
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 @@ | ||
label=日本語 |
74 changes: 74 additions & 0 deletions
74
...ration-tests/common-test-code/src/test/java/com/vaadin/flow/quarkus/it/TranslationIT.java
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,74 @@ | ||
/* | ||
* Copyright 2000-2024 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.vaadin.flow.quarkus.it; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.vaadin.flow.component.html.testbench.SpanElement; | ||
import com.vaadin.flow.quarkus.it.i18n.TranslationView; | ||
import com.vaadin.flow.test.AbstractChromeIT; | ||
|
||
@QuarkusIntegrationTest | ||
public class TranslationIT extends AbstractChromeIT { | ||
@Override | ||
protected String getTestPath() { | ||
return "/translations"; | ||
} | ||
|
||
@Test | ||
public void translationFilesExist_defaultI18NInstantiated_languagesWork() { | ||
open(); | ||
|
||
String locales = $(SpanElement.class).id(TranslationView.LOCALES_ID) | ||
.getText(); | ||
Assertions.assertTrue(locales.contains("de"), | ||
"Couldn't verify German locale"); | ||
Assertions.assertTrue(locales.contains("fi_FI"), | ||
"Couldn't verify Finnish locale"); | ||
Assertions.assertTrue(locales.contains("fr_FR"), | ||
"Couldn't verify French locale"); | ||
Assertions.assertTrue(locales.contains("ja_JP"), | ||
"Couldn't verify Japanese locale"); | ||
|
||
Assertions.assertEquals("Default", | ||
$(SpanElement.class).id("english").getText()); | ||
Assertions.assertEquals("Deutsch", | ||
$(SpanElement.class).id("german").getText()); | ||
Assertions.assertEquals("Deutsch", | ||
$(SpanElement.class).id("germany").getText()); | ||
Assertions.assertEquals("Suomi", | ||
$(SpanElement.class).id("finnish").getText()); | ||
Assertions.assertEquals("français", | ||
$(SpanElement.class).id("french").getText()); | ||
Assertions.assertEquals("日本語", | ||
$(SpanElement.class).id("japanese").getText()); | ||
} | ||
|
||
@Test | ||
public void translationFilesExist_defaultI18NInstantiated_updateFromExternalThreadWorks() { | ||
open(); | ||
|
||
waitUntilNot(driver -> $(SpanElement.class).id("dynamic").getText() | ||
.equals("waiting")); | ||
|
||
Assertions.assertEquals("français", | ||
$(SpanElement.class).id("dynamic").getText(), | ||
"Dynamic update from thread should have used correct bundle."); | ||
} | ||
} |
Oops, something went wrong.