use of org.apache.sis.util.iso.DefaultInternationalString in project sis by apache.
the class PT_FreeText method create.
/**
* Constructs a {@linkplain TextGroup text group} from the given {@link InternationalString}
* if it contains at least one non-root locale. Otherwise returns {@code null}, meaning that
* the simpler {@link GO_CharacterString} construct should be used instead.
*
* @param text an international string which could have several translations embedded for the same text.
* @return a {@code PT_FreeText} instance if the given text has several translations, or {@code null} otherwise.
*/
public static PT_FreeText create(final InternationalString text) {
if (text instanceof DefaultInternationalString) {
final DefaultInternationalString df = (DefaultInternationalString) text;
final Set<Locale> locales = df.getLocales();
final TextGroup[] textGroup = new TextGroup[locales.size()];
int n = 0;
for (final Locale locale : locales) {
if (locale != null && !locale.equals(Locale.ROOT)) {
textGroup[n++] = new TextGroup(locale, text.toString(locale));
}
}
if (n != 0) {
/*
* Invoke toString(Locale) instead than toString() even if the locale is null,
* since the desired fallback is typically Locale.ROOT instead than the system
* default. It is usually safer to avoid null value, but in this particular case
* the implementation (DefaultInternationalString) is known to support null.
*/
final Context context = Context.current();
return new PT_FreeText(df.toString(context != null ? context.getLocale() : null), ArraysExt.resize(textGroup, n));
}
}
return null;
}
use of org.apache.sis.util.iso.DefaultInternationalString in project sis by apache.
the class DefaultCitationTest method create.
/**
* Creates a citation with an arbitrary title, presentation form and other properties.
*
* @return an arbitrary citation.
*
* @since 0.7
*/
public static DefaultCitation create() {
final DefaultCitation citation = new DefaultCitation();
final DefaultInternationalString title = new DefaultInternationalString();
title.add(Locale.JAPANESE, "アンダーカレント");
title.add(Locale.ENGLISH, "Undercurrent");
citation.setTitle(title);
citation.setISBN("9782505004509");
citation.setPresentationForms(Arrays.asList(PresentationForm.DOCUMENT_HARDCOPY, PresentationForm.DOCUMENT_DIGITAL));
citation.setAlternateTitles(Collections.singleton(// Actually a different script of the Japanese title.
new SimpleInternationalString("Andākarento")));
final DefaultResponsibleParty author = new DefaultResponsibleParty(Role.AUTHOR);
author.setParties(Collections.singleton(new DefaultIndividual("Testsuya Toyoda", null, null)));
final DefaultResponsibleParty editor = new DefaultResponsibleParty(Role.valueOf("EDITOR"));
editor.setParties(Collections.singleton(new DefaultOrganisation("Kōdansha", null, null, null)));
editor.setExtents(Collections.singleton(Extents.WORLD));
citation.setCitedResponsibleParties(Arrays.asList(author, editor));
return citation;
}
use of org.apache.sis.util.iso.DefaultInternationalString in project sis by apache.
the class TreeTableFormatTest method testLocalizedFormatInEnglishEnvironment.
/**
* Implementation of {@link #testLocalizedFormat()}, to be executed only after the default locale
* has been forced to English. The later is necessary as long as the GeoAPI elements tested below
* do not have translations in all tested languages.
*/
private static void testLocalizedFormatInEnglishEnvironment() {
final DefaultInternationalString i18n = new DefaultInternationalString();
i18n.add(Locale.ENGLISH, "An English sentence");
i18n.add(Locale.FRENCH, "Une phrase en français");
i18n.add(Locale.JAPANESE, "日本語の言葉");
final DefaultTreeTable table = new DefaultTreeTable(NAME, VALUE);
final TreeTable.Node root = table.getRoot();
root.setValue(NAME, "Root");
TreeTable.Node child;
child = root.newChild();
child.setValue(NAME, "CodeList");
child.setValue(VALUE, Role.POINT_OF_CONTACT);
child = root.newChild();
child.setValue(NAME, "Enum");
child.setValue(VALUE, RoundingMode.HALF_DOWN);
child = root.newChild();
child.setValue(NAME, "i18n");
child.setValue(VALUE, i18n);
TreeTableFormat tf = new TreeTableFormat(null, null);
assertMultilinesEquals("Root\n" + " ├─CodeList…… Point of contact\n" + " ├─Enum……………… Half down\n" + " └─i18n……………… An English sentence\n", tf.format(table));
tf = new TreeTableFormat(Locale.FRENCH, null);
assertMultilinesEquals("Root\n" + // Not yet localized.
" ├─CodeList…… Point of contact\n" + // No localization provided.
" ├─Enum……………… Half down\n" + " └─i18n……………… Une phrase en français\n", tf.format(table));
tf = new TreeTableFormat(Locale.JAPANESE, null);
assertMultilinesEquals("Root\n" + // Not yet localized.
" ├─CodeList…… Point of contact\n" + // No localization provided.
" ├─Enum……………… Half down\n" + " └─i18n……………… 日本語の言葉\n", tf.format(table));
}
use of org.apache.sis.util.iso.DefaultInternationalString in project sis by apache.
the class StringAdapterTest method testToLocalizedString.
/**
* Tests {@link StringAdapter#toString(CharSequence)} for an {@link org.opengis.util.InternationalString}
* having localizations in different languages.
*/
@Test
@DependsOnMethod("testToUnlocalizedString")
public void testToLocalizedString() {
final DefaultInternationalString i18n = new DefaultInternationalString();
i18n.add(Locale.ENGLISH, "A word");
i18n.add(Locale.FRENCH, "Un mot");
i18n.add(Locale.JAPANESE, "言葉");
final Context context = new Context(0, Locale.ENGLISH, null, null, null, null, null, null, null);
try {
Context.push(Locale.JAPANESE);
assertEquals("言葉", StringAdapter.toString(i18n));
Context.push(Locale.FRENCH);
assertEquals("Un mot", StringAdapter.toString(i18n));
Context.push(Locale.ENGLISH);
assertEquals("A word", StringAdapter.toString(i18n));
Context.pull();
assertEquals("Un mot", StringAdapter.toString(i18n));
Context.pull();
assertEquals("言葉", StringAdapter.toString(i18n));
Context.pull();
assertEquals("A word", StringAdapter.toString(i18n));
} finally {
context.finish();
}
}
use of org.apache.sis.util.iso.DefaultInternationalString in project sis by apache.
the class FreeTextMarshallingTest method getExpectedI18N.
/**
* Returns the expected string.
*/
private static DefaultInternationalString getExpectedI18N() {
final DefaultInternationalString i18n = new DefaultInternationalString();
i18n.add(Locale.ENGLISH, "OpenSource Project");
i18n.add(Locale.FRENCH, "Projet OpenSource");
i18n.add(Locale.ITALIAN, "Progetto OpenSource");
return i18n;
}
Aggregations