From fec261ad242495e3569c92dfb94ee0c5dbb6d93f Mon Sep 17 00:00:00 2001 From: Michiel Meeuwissen Date: Sat, 24 Feb 2024 22:06:14 +0100 Subject: [PATCH] Added an enum for the iso part 1 languages. --- pom.xml | 17 +- .../org/meeuw/i18n/languages/ISO_639_1.java | 1131 +++++++++++++++++ .../meeuw/i18n/languages/LanguageCode.java | 6 +- src/test/java/module-info.java | 2 + .../i18n/languages/test/GenerateEnum.java | 57 + .../i18n/languages/test/LanguageCodeTest.java | 5 +- .../java/org/meeuw/test/jackson/iso639.java | 3 +- .../src/main/java/org/meeuw/test/iso639.java | 2 + 8 files changed, 1215 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/meeuw/i18n/languages/ISO_639_1.java create mode 100644 src/test/java/org/meeuw/i18n/languages/test/GenerateEnum.java diff --git a/pom.xml b/pom.xml index 45077cd..29c34bf 100644 --- a/pom.xml +++ b/pom.xml @@ -7,13 +7,13 @@ 2.2-SNAPSHOT jar i18n-iso-639-3 - Provides an enum with ISO 639-3 languages - https://github.com/mihxil/i18n-iso-639-2 + Provides a class with one instance of every of the ISO 639-3 languages + https://github.com/mihxil/i18n-iso-639-3 Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt + https://www.apache.org/licenses/LICENSE-2.0.txt repo A business-friendly OSS license @@ -131,6 +131,13 @@ 2.16.1 true + + + org.glassfish.jaxb + codemodel + ${codemodel.version} + test + @@ -138,7 +145,7 @@ maven-compiler-plugin - 3.11.0 + 3.12.1 11 11 @@ -166,7 +173,7 @@ maven-surefire-plugin - 3.2.2 + 3.2.5 false diff --git a/src/main/java/org/meeuw/i18n/languages/ISO_639_1.java b/src/main/java/org/meeuw/i18n/languages/ISO_639_1.java new file mode 100644 index 0000000..e429427 --- /dev/null +++ b/src/main/java/org/meeuw/i18n/languages/ISO_639_1.java @@ -0,0 +1,1131 @@ +package org.meeuw.i18n.languages; + + + +/** + * This class is automatically generated.It contains the ISO 639-1 language codes. + * + */ +public enum ISO_639_1 { + + + /** + * ab Abkhazian + * + */ + ab, + + /** + * aa Afar + * + */ + aa, + + /** + * af Afrikaans + * + */ + af, + + /** + * ak Akan + * + */ + ak, + + /** + * sq Albanian + * + */ + sq, + + /** + * am Amharic + * + */ + am, + + /** + * ar Arabic + * + */ + ar, + + /** + * an Aragonese + * + */ + an, + + /** + * hy Armenian + * + */ + hy, + + /** + * as Assamese + * + */ + as, + + /** + * av Avaric + * + */ + av, + + /** + * ae Avestan + * + */ + ae, + + /** + * ay Aymara + * + */ + ay, + + /** + * az Azerbaijani + * + */ + az, + + /** + * bm Bambara + * + */ + bm, + + /** + * ba Bashkir + * + */ + ba, + + /** + * eu Basque + * + */ + eu, + + /** + * be Belarusian + * + */ + be, + + /** + * bn Bengali + * + */ + bn, + + /** + * bi Bislama + * + */ + bi, + + /** + * bs Bosnian + * + */ + bs, + + /** + * br Breton + * + */ + br, + + /** + * bg Bulgarian + * + */ + bg, + + /** + * my Burmese + * + */ + my, + + /** + * ch Chamorro + * + */ + ch, + + /** + * ce Chechen + * + */ + ce, + + /** + * zh Chinese + * + */ + zh, + + /** + * cv Chuvash + * + */ + cv, + + /** + * kw Cornish + * + */ + kw, + + /** + * co Corsican + * + */ + co, + + /** + * cr Cree + * + */ + cr, + + /** + * ht Haitian Creole + * + */ + ht, + + /** + * hr Croatian + * + */ + hr, + + /** + * cs Czech + * + */ + cs, + + /** + * da Danish + * + */ + da, + + /** + * dz Dzongkha + * + */ + dz, + + /** + * en English + * + */ + en, + + /** + * eo Esperanto + * + */ + eo, + + /** + * et Estonian + * + */ + et, + + /** + * ee Ewe + * + */ + ee, + + /** + * fo Faroese + * + */ + fo, + + /** + * fj Fijian + * + */ + fj, + + /** + * fi Finnish + * + */ + fi, + + /** + * nl Flemish + * + */ + nl, + + /** + * fr French + * + */ + fr, + + /** + * fy Western Frisian + * + */ + fy, + + /** + * ff Fulah + * + */ + ff, + + /** + * gd Scottish Gaelic + * + */ + gd, + + /** + * gl Galician + * + */ + gl, + + /** + * lg Ganda + * + */ + lg, + + /** + * ka Georgian + * + */ + ka, + + /** + * de German + * + */ + de, + + /** + * el Modern Greek (1453-) + * + */ + el, + + /** + * gn Guarani + * + */ + gn, + + /** + * gu Gujarati + * + */ + gu, + + /** + * ha Hausa + * + */ + ha, + + /** + * he Hebrew + * + */ + he, + + /** + * hz Herero + * + */ + hz, + + /** + * hi Hindi + * + */ + hi, + + /** + * ho Hiri Motu + * + */ + ho, + + /** + * hu Hungarian + * + */ + hu, + + /** + * is Icelandic + * + */ + is, + + /** + * io Ido + * + */ + io, + + /** + * ig Igbo + * + */ + ig, + + /** + * id Indonesian + * + */ + id, + + /** + * ia Interlingua (International Auxiliary Language Association) + * + */ + ia, + + /** + * iu Inuktitut + * + */ + iu, + + /** + * ik Inupiaq + * + */ + ik, + + /** + * ga Irish + * + */ + ga, + + /** + * it Italian + * + */ + it, + + /** + * ja Japanese + * + */ + ja, + + /** + * jv Javanese + * + */ + jv, + + /** + * kl Kalaallisut + * + */ + kl, + + /** + * kn Kannada + * + */ + kn, + + /** + * kr Kanuri + * + */ + kr, + + /** + * ks Kashmiri + * + */ + ks, + + /** + * kk Kazakh + * + */ + kk, + + /** + * km Khmer + * + */ + km, + + /** + * ki Kikuyu + * + */ + ki, + + /** + * rw Kinyarwanda + * + */ + rw, + + /** + * kv Komi + * + */ + kv, + + /** + * kg Kongo + * + */ + kg, + + /** + * ko Korean + * + */ + ko, + + /** + * ku Kurdish + * + */ + ku, + + /** + * kj Kwanyama + * + */ + kj, + + /** + * ky Kyrgyz + * + */ + ky, + + /** + * lo Lao + * + */ + lo, + + /** + * la Latin + * + */ + la, + + /** + * lv Latvian + * + */ + lv, + + /** + * li Limburgish + * + */ + li, + + /** + * ln Lingala + * + */ + ln, + + /** + * lt Lithuanian + * + */ + lt, + + /** + * lu Luba-Katanga + * + */ + lu, + + /** + * lb Luxembourgish + * + */ + lb, + + /** + * mk Macedonian + * + */ + mk, + + /** + * mg Malagasy + * + */ + mg, + + /** + * ms Malay (macrolanguage) + * + */ + ms, + + /** + * ml Malayalam + * + */ + ml, + + /** + * dv Maldivian + * + */ + dv, + + /** + * mt Maltese + * + */ + mt, + + /** + * gv Manx + * + */ + gv, + + /** + * mi Maori + * + */ + mi, + + /** + * mr Marathi + * + */ + mr, + + /** + * mh Marshallese + * + */ + mh, + + /** + * mn Mongolian + * + */ + mn, + + /** + * na Nauru + * + */ + na, + + /** + * nv Navajo + * + */ + nv, + + /** + * nd North Ndebele + * + */ + nd, + + /** + * nr South Ndebele + * + */ + nr, + + /** + * ng Ndonga + * + */ + ng, + + /** + * ne Nepali (macrolanguage) + * + */ + ne, + + /** + * no Norwegian + * + */ + no, + + /** + * nb Norwegian Bokmål + * + */ + nb, + + /** + * nn Norwegian Nynorsk + * + */ + nn, + + /** + * ny Nyanja + * + */ + ny, + + /** + * ie Occidental + * + */ + ie, + + /** + * oc Occitan (post 1500) + * + */ + oc, + + /** + * oj Ojibwa + * + */ + oj, + + /** + * or Oriya (macrolanguage) + * + */ + or, + + /** + * om Oromo + * + */ + om, + + /** + * os Ossetic + * + */ + os, + + /** + * pi Pali + * + */ + pi, + + /** + * fa Persian + * + */ + fa, + + /** + * pl Polish + * + */ + pl, + + /** + * pt Portuguese + * + */ + pt, + + /** + * pa Punjabi + * + */ + pa, + + /** + * ps Pushto + * + */ + ps, + + /** + * qu Quechua + * + */ + qu, + + /** + * ro Romanian + * + */ + ro, + + /** + * rm Romansh + * + */ + rm, + + /** + * rn Rundi + * + */ + rn, + + /** + * ru Russian + * + */ + ru, + + /** + * se Northern Sami + * + */ + se, + + /** + * sm Samoan + * + */ + sm, + + /** + * sg Sango + * + */ + sg, + + /** + * sa Sanskrit + * + */ + sa, + + /** + * sc Sardinian + * + */ + sc, + + /** + * sr Serbian + * + */ + sr, + + /** + * sh Serbo-Croatian + * + */ + sh, + + /** + * sn Shona + * + */ + sn, + + /** + * sd Sindhi + * + */ + sd, + + /** + * si Sinhalese + * + */ + si, + + /** + * cu Old Slavonic + * + */ + cu, + + /** + * sk Slovak + * + */ + sk, + + /** + * sl Slovenian + * + */ + sl, + + /** + * so Somali + * + */ + so, + + /** + * st Southern Sotho + * + */ + st, + + /** + * es Spanish + * + */ + es, + + /** + * su Sundanese + * + */ + su, + + /** + * sw Swahili (macrolanguage) + * + */ + sw, + + /** + * ss Swati + * + */ + ss, + + /** + * sv Swedish + * + */ + sv, + + /** + * tl Tagalog + * + */ + tl, + + /** + * ty Tahitian + * + */ + ty, + + /** + * tg Tajik + * + */ + tg, + + /** + * ta Tamil + * + */ + ta, + + /** + * tt Tatar + * + */ + tt, + + /** + * te Telugu + * + */ + te, + + /** + * th Thai + * + */ + th, + + /** + * bo Tibetan + * + */ + bo, + + /** + * ti Tigrinya + * + */ + ti, + + /** + * to Tonga (Tonga Islands) + * + */ + to, + + /** + * ts Tsonga + * + */ + ts, + + /** + * tn Tswana + * + */ + tn, + + /** + * tr Turkish + * + */ + tr, + + /** + * tk Turkmen + * + */ + tk, + + /** + * tw Twi + * + */ + tw, + + /** + * uk Ukrainian + * + */ + uk, + + /** + * ur Urdu + * + */ + ur, + + /** + * ug Uyghur + * + */ + ug, + + /** + * uz Uzbek + * + */ + uz, + + /** + * ca Valencian + * + */ + ca, + + /** + * ve Venda + * + */ + ve, + + /** + * vi Vietnamese + * + */ + vi, + + /** + * vo Volapük + * + */ + vo, + + /** + * wa Walloon + * + */ + wa, + + /** + * cy Welsh + * + */ + cy, + + /** + * wo Wolof + * + */ + wo, + + /** + * xh Xhosa + * + */ + xh, + + /** + * ii Sichuan Yi + * + */ + ii, + + /** + * yi Yiddish + * + */ + yi, + + /** + * yo Yoruba + * + */ + yo, + + /** + * za Zhuang + * + */ + za, + + /** + * zu Zulu + * + */ + zu; + private final LanguageCode languageCode; + + ISO_639_1() { + this.languageCode = LanguageCode.languageCode(this.name()); + } + + public LanguageCode getLanguageCode() { + return languageCode; + } + + @Override + public String toString() { + return languageCode.toString(); + } + +} + \ No newline at end of file diff --git a/src/main/java/org/meeuw/i18n/languages/LanguageCode.java b/src/main/java/org/meeuw/i18n/languages/LanguageCode.java index bb21102..869f798 100644 --- a/src/main/java/org/meeuw/i18n/languages/LanguageCode.java +++ b/src/main/java/org/meeuw/i18n/languages/LanguageCode.java @@ -17,7 +17,7 @@ *

* Annotated with {@link XmlJavaTypeAdapter}, so it will automatically be marshalled and unmarshalled in XML's. *

- * Also annotated with jackon annotation, to be marshalled and unmarshalled in JSON as the code. + * Also annotated with jackson annotation, to be marshalled and unmarshalled in JSON as the code. *

* This class is immutable and can be used as a key in maps. */ @@ -315,6 +315,10 @@ public String getPart2T() { public String getPart1() { return part1; } + + public ISO_639_1 getISO_639_1() { + return part1 == null ? null : ISO_639_1.valueOf(part1); + } public Scope getScope() { return scope; diff --git a/src/test/java/module-info.java b/src/test/java/module-info.java index 8ad42e7..18c7313 100644 --- a/src/test/java/module-info.java +++ b/src/test/java/module-info.java @@ -10,6 +10,8 @@ requires org.junit.jupiter.params; requires jakarta.validation; + requires com.fasterxml.jackson.core; requires com.fasterxml.jackson.databind; + requires com.sun.codemodel; } diff --git a/src/test/java/org/meeuw/i18n/languages/test/GenerateEnum.java b/src/test/java/org/meeuw/i18n/languages/test/GenerateEnum.java new file mode 100644 index 0000000..893c08e --- /dev/null +++ b/src/test/java/org/meeuw/i18n/languages/test/GenerateEnum.java @@ -0,0 +1,57 @@ +package org.meeuw.i18n.languages.test; + +import com.sun.codemodel.*; +import com.sun.codemodel.writer.OutputStreamCodeWriter; +import java.io.IOException; +import org.junit.jupiter.api.Test; +import org.meeuw.i18n.languages.LanguageCode; + +public class GenerateEnum { + + @Test + public void createEnum() throws JClassAlreadyExistsException, IOException { + + + JCodeModel model = new JCodeModel(); + JDefinedClass iso639_1 = model._class("org.meeuw.i18n.languages.ISO_639_1", ClassType.ENUM); + + iso639_1.javadoc() + .append("This class is automatically generated.") + .append("It contains the ISO 639-1 language codes."); + + + + JFieldVar languageCode1 = iso639_1.field(JMod.PRIVATE | JMod.FINAL, LanguageCode.class, "languageCode"); + + JMethod constructor = iso639_1.constructor(JMod.NONE); + JBlock body = constructor.body(); + body.assign( + JExpr._this().ref(languageCode1), + model.ref(LanguageCode.class).staticInvoke("languageCode").arg(JExpr._this().invoke("name")) + ); + + JMethod getter = iso639_1.method(JMod.PUBLIC, LanguageCode.class, "getLanguageCode"); + getter.body()._return(languageCode1); + + JMethod toString = iso639_1.method(JMod.PUBLIC, String.class, "toString"); + toString.annotate(Override.class); + toString.body()._return(languageCode1.invoke("toString")); + + + + LanguageCode.stream() + .sorted() + .filter(lc -> lc.getPart1() != null) + .forEach(languageCode -> { + + JEnumConstant enumConstant = iso639_1.enumConstant(languageCode.getPart1()); + enumConstant.javadoc().append(languageCode.getPart1() + " " + languageCode.getName()); + } + ); + + model.build(new OutputStreamCodeWriter(System.out, "UTF-8")); + + + } +} + \ No newline at end of file diff --git a/src/test/java/org/meeuw/i18n/languages/test/LanguageCodeTest.java b/src/test/java/org/meeuw/i18n/languages/test/LanguageCodeTest.java index 5d3a905..379ff6b 100644 --- a/src/test/java/org/meeuw/i18n/languages/test/LanguageCodeTest.java +++ b/src/test/java/org/meeuw/i18n/languages/test/LanguageCodeTest.java @@ -15,7 +15,10 @@ public void stream() { assertThat(lc.getCode()).isNotNull(); assertThat(lc.getLanguageType()).isNotNull(); assertThat(lc.getScope()).isNotNull(); - + + if (lc.getPart1() != null) { + System.out.println("Part1: " + lc.getISO_639_1()); + } if (lc.getComment() != null) { System.out.println("Comment: " + lc.getComment()); diff --git a/test/jackson/src/main/java/org/meeuw/test/jackson/iso639.java b/test/jackson/src/main/java/org/meeuw/test/jackson/iso639.java index 159d1a6..b349506 100644 --- a/test/jackson/src/main/java/org/meeuw/test/jackson/iso639.java +++ b/test/jackson/src/main/java/org/meeuw/test/jackson/iso639.java @@ -20,11 +20,12 @@ public static void main(String[] args) { String code; if (args.length == 0) { System.out.println("Usage: iso639 "); + System.out.println("Showing json marshalling of language code using jackson"); code = "nld"; } else { code = args[0]; } - Container languageContainer = LanguageCode.get(code).map(c -> new Container(c)).orElseThrow(); + Container languageContainer = LanguageCode.get(code).map(Container::new).orElseThrow(); System.out.println( code + " -> " + languageContainer.language + "\n" + new ObjectMapper().valueToTree(languageContainer)); diff --git a/test/simple/src/main/java/org/meeuw/test/iso639.java b/test/simple/src/main/java/org/meeuw/test/iso639.java index 419f13a..2f4fc35 100644 --- a/test/simple/src/main/java/org/meeuw/test/iso639.java +++ b/test/simple/src/main/java/org/meeuw/test/iso639.java @@ -10,6 +10,8 @@ public static void main(String[] args) { String code; if (args.length == 0) { System.out.println("Usage: iso639 "); + System.out.println("Showing that it works with no dependencies"); + code = "nld"; } else { code = args[0];