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

fi.evolver.ai.vaadin.component.i18n.UploadI18nFactory Maven / Gradle / Ivy

There is a newer version: 1.5.5
Show newest version
package fi.evolver.ai.vaadin.component.i18n;

import java.util.Arrays;

import com.vaadin.flow.component.upload.UploadI18N;
import com.vaadin.flow.component.upload.UploadI18N.*;

public class UploadI18nFactory {
	public static UploadI18N getI18n(VaadinTranslations t) {
		return getI18n(t, null);
	}

	public static UploadI18N getI18n(VaadinTranslations t, String maxFileSize) {
		UploadI18N i18n = new UploadI18N();
		i18n.setAddFiles(getAddFiles(t));
		i18n.setDropFiles(getDropFiles(t));
		i18n.setError(getError(t, maxFileSize));
		i18n.setFile(getFile(t));
		i18n.setUnits(getUnits(t));
		i18n.setUploading(getUploading(t));
		return i18n;
	}

	protected static AddFiles getAddFiles(VaadinTranslations t) {
		AddFiles i18n = new AddFiles();
		i18n.setOne(t.getTranslation("vaadin.upload.addFiles.one"));
		i18n.setMany(t.getTranslation("vaadin.upload.addFiles.many"));
		return i18n;
	}

	protected static DropFiles getDropFiles(VaadinTranslations t) {
		DropFiles i18n = new DropFiles();
		i18n.setOne(t.getTranslation("vaadin.upload.dropFiles.one"));
		i18n.setMany(t.getTranslation("vaadin.upload.dropFiles.many"));
		return i18n;
	}

	protected static UploadI18N.Error getError(VaadinTranslations t, String maxFileSize) {
		UploadI18N.Error i18n = new UploadI18N.Error();
		if (maxFileSize != null)
			i18n.setFileIsTooBig(t.getTranslation("vaadin.upload.error.fileTooLargeWithSize", maxFileSize));
		else
			i18n.setFileIsTooBig(t.getTranslation("vaadin.upload.error.fileTooLarge"));
		i18n.setIncorrectFileType(t.getTranslation("vaadin.upload.error.incorrectFileType"));
		i18n.setTooManyFiles(t.getTranslation("vaadin.upload.error.tooManyFiles"));
		return i18n;
	}

	protected static File getFile(VaadinTranslations t) {
		File i18n = new File();
		i18n.setRemove(t.getTranslation("vaadin.upload.file.remove"));
		i18n.setRetry(t.getTranslation("vaadin.upload.file.retry"));
		i18n.setStart(t.getTranslation("vaadin.upload.file.start"));
		return i18n;
	}

	protected static Units getUnits(VaadinTranslations t) {
		Units i18n = new Units();
		i18n.setSize(Arrays.asList("B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"));
		return i18n;
	}

	protected static Uploading getUploading(VaadinTranslations t) {
		Uploading i18n = new Uploading();
		i18n.setError(getUploadingError(t));
		i18n.setRemainingTime(getUploadingRemainingTime(t));
		i18n.setStatus(getUploadingStatus(t));
		return i18n;
	}

	protected static Uploading.Error getUploadingError(VaadinTranslations t) {
		Uploading.Error i18n = new Uploading.Error();
		i18n.setForbidden(t.getTranslation("vaadin.upload.uploading.error.forbidden"));
		i18n.setServerUnavailable(t.getTranslation("vaadin.upload.uploading.error.serverUnavailable"));
		i18n.setUnexpectedServerError(t.getTranslation("vaadin.upload.uploading.error.unexpectedServerError"));
		return i18n;
	}

	protected static Uploading.RemainingTime getUploadingRemainingTime(VaadinTranslations t) {
		Uploading.RemainingTime i18n = new Uploading.RemainingTime();
		i18n.setPrefix(t.getTranslation("vaadin.upload.uploading.remainingTime.prefix"));
		i18n.setUnknown(t.getTranslation("vaadin.upload.uploading.remainingTime.unknown"));
		return i18n;
	}

	protected static Uploading.Status getUploadingStatus(VaadinTranslations t) {
		Uploading.Status i18n = new Uploading.Status();
		i18n.setConnecting(t.getTranslation("vaadin.upload.uploading.status.connecting"));
		i18n.setHeld(t.getTranslation("vaadin.upload.uploading.status.held"));
		i18n.setProcessing(t.getTranslation("vaadin.upload.uploading.status.processing"));
		i18n.setStalled(t.getTranslation("vaadin.upload.uploading.status.stalled"));
		return i18n;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy