All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.core.i18n.I18nKeyDisplayString Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.core.i18n;

import com.softicar.platform.common.core.i18n.key.II18nKey;
import com.softicar.platform.common.core.locale.CurrentLocale;

/**
 * Maps an {@link II18nKey} into an {@link IDisplayString}.
 *
 * @author Oliver Richers
 */
class I18nKeyDisplayString implements IDisplayString {

	private final II18nKey key;
	private final Object[] arguments;

	public I18nKeyDisplayString(II18nKey key, Object...arguments) {

		this.key = key;
		this.arguments = new I18nFormatArgumentsLocalizer(arguments).localize();
	}

	@Override
	public String toString() {

		return key//
			.toLanguage(CurrentLocale.get().getLanguage())
			.map(this::formatString)
			.orElseGet(this::getFallbackTranslation);
	}

	private String formatString(String string) {

		return String.format(string, arguments);
	}

	private String getFallbackTranslation() {

		return InternalI18nTranslator.translate(key.toEnglish(), arguments);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy