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

com.squarespace.cldrengine.internal.DefaultResourcePackLoader Maven / Gradle / Ivy

The newest version!
package com.squarespace.cldrengine.internal;

import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;

import com.google.gson.JsonObject;
import com.squarespace.cldrengine.ResourcePack;
import com.squarespace.cldrengine.ResourcePackLoader;
import com.squarespace.cldrengine.utils.JsonUtils;

/**
 * Loads the bundled resources from the Jar.
 */
public class DefaultResourcePackLoader implements ResourcePackLoader {

  private static final ConcurrentHashMap PACKS = new ConcurrentHashMap<>();

  public ResourcePack get(String language) {
    return PACKS.computeIfAbsent(language, lang -> {
      String name = language + ".json";
      try {
        JsonObject obj = JsonUtils.loadJsonResource(DefaultResourcePackLoader.class, name);
        return obj == null ? null : new ResourcePack(obj);
      } catch (IOException e) {
        throw new RuntimeException("Fatal: failed to load resource pack: '" + name + "'", e);
      }
    });
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy