Skip to content

Commit

Permalink
Support for display names.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Oct 6, 2024
1 parent 5509309 commit 494b089
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/org/meeuw/i18n/languages/DisplayNames_en.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.meeuw.i18n.languages;

import java.util.stream.Stream;

public class DisplayNames_en extends java.util.ListResourceBundle {
@Override
protected Object[][] getContents() {
return Stream.concat(
Stream.of(ISO_639_1_Code.values()),
ISO_639_3_Code.stream())
.map(i -> new Object[] {i.code(), i.refName()})
.toArray(i -> new Object[i][2]);

}
}
7 changes: 7 additions & 0 deletions src/main/java/org/meeuw/i18n/languages/ISO_639_Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serializable;
import java.util.Locale;
import java.util.ResourceBundle;

import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

Expand Down Expand Up @@ -56,4 +57,10 @@ static ISO_639_Code fromCode(String code) {
}


default String getDisplayName(Locale locale) {
ResourceBundle bundle = ResourceBundle.getBundle("org.meeuw.i18n.languages.DisplayNames", locale);
return bundle.getString(code());

}

}
2 changes: 2 additions & 0 deletions src/main/java/org/meeuw/i18n/languages/LanguageCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ default NameRecord nameRecord(Locale locale) {
}
}



/**
* The macro language(s) of which this language is a part.
* @return a list of macro languages, or an empty list if this language is not known to be a part of a macro language.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dse=Nederlandse Gebarentaal
vgt=Vlaamse Gebarentaal
ase=Amerikaanse Gebarentaal
bfi=Britse Gebarentaal
csl=Chinese Gebarentaal
gsg=Duitse Gebarentaal
tsm=Turkse Gebarentaal
16 changes: 16 additions & 0 deletions src/test/java/org/meeuw/i18n/languages/test/LanguageCodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.meeuw.i18n.languages.*;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -210,6 +212,20 @@ public void deprecated() {
assertThat(LanguageCode.getByPart3("nld")).contains((LanguageCode) ISO_639.get("nl").get());
}

@ParameterizedTest
@ValueSource(strings = {"dse"})
public void signLanguage(String code) {
LanguageCode l = LanguageCode.get(code).orElseThrow();

assertThat(l.refName()).isEqualTo("Dutch Sign Language");
assertThat(l.nameRecord().print()).isEqualTo("dse (Dutch Sign Language)");
assertThat(new Locale(l.code()).getDisplayName(Locale.US)).isEqualTo("dse");

assertThat(l.getDisplayName(Locale.US)).isEqualTo("Dutch Sign Language");

assertThat(l.getDisplayName(new Locale("nl"))).isEqualTo("Nederlandse Gebarentaal");
}


// TODO
@Disabled
Expand Down

0 comments on commit 494b089

Please sign in to comment.