diff --git a/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java b/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java index 78c9a00e75..543838c487 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java +++ b/impl/src/main/java/com/sun/faces/application/resource/ClasspathResourceHelper.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import com.sun.faces.config.WebConfiguration; import com.sun.faces.util.Util; @@ -112,19 +113,14 @@ protected InputStream getNonCompressedInputStream(ResourceInfo resource, FacesCo if (ctx.isProjectStage(Development)) { ClassLoader loader = Util.getCurrentLoader(getClass()); String path = resource.getPath(); - if (loader.getResource(path) != null) { - in = loader.getResource(path).openStream(); - } - if (in == null && getClass().getClassLoader().getResource(path) != null) { - in = getClass().getClassLoader().getResource(path).openStream(); + URL url = getResourceURL(loader, path, ctx); + if (url != null) { + in = url.openStream(); } } else { ClassLoader loader = Util.getCurrentLoader(getClass()); String path = resource.getPath(); - in = loader.getResourceAsStream(path); - if (in == null) { - in = getClass().getClassLoader().getResourceAsStream(path); - } + in = getResourceAsStream(loader, path, ctx); } return in; } @@ -330,4 +326,44 @@ private URL findPathConsideringContracts(ClassLoader loader, LibraryInfo library return result; } + private InputStream getResourceAsStream(ClassLoader loader, String path, FacesContext ctx) { + InputStream in = null; + List localizedPaths = getLocalizedPaths(path, ctx); + for (String path_: localizedPaths) { + in = getResourceAsStream(loader, path_); + if (in != null) { + break; + } + } + return in; + } + + private URL getResourceURL(ClassLoader loader, String path, FacesContext ctx) { + List localizedPaths = getLocalizedPaths(path, ctx); + URL url = null; + for (String path_: localizedPaths) { + url = getResource_(loader, path_); + if (url != null) { + break; + } + } + return url; + } + + private InputStream getResourceAsStream(ClassLoader loader, String path) { + InputStream in = loader.getResourceAsStream(path); + if (in == null) { + in = getClass().getClassLoader().getResourceAsStream(path); + } + return in; + } + + private URL getResource_(ClassLoader loader, String path) { + URL res = loader.getResource(path); + if (res == null) { + res = getClass().getClassLoader().getResource(path); + } + return res; + } + } diff --git a/impl/src/main/java/com/sun/faces/application/resource/ResourceHelper.java b/impl/src/main/java/com/sun/faces/application/resource/ResourceHelper.java index 31d34aa5f2..7c84420def 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/ResourceHelper.java +++ b/impl/src/main/java/com/sun/faces/application/resource/ResourceHelper.java @@ -35,6 +35,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -705,4 +706,24 @@ private boolean isPropertyValid(String property) { } // END ELEvaluatingInputStream + protected List getLocalizedPaths(String path, FacesContext ctx) { + Locale loc = (ctx != null && ctx.getViewRoot() != null) ? ctx.getViewRoot().getLocale() : null; + if (!path.endsWith(".properties") || loc == null) { + return Collections.singletonList(path); + } + List list = new ArrayList<>(); + String base = path.substring(0, path.lastIndexOf(".properties")); + if (!loc.getVariant().isEmpty()) { + list.add(String.format("%s_%s_%s_%s.properties", base, loc.getLanguage(), loc.getCountry(), loc.getVariant())); + } + if (!loc.getCountry().isEmpty()) { + list.add(String.format("%s_%s_%s.properties", base, loc.getLanguage(), loc.getCountry())); + } + if (!loc.getLanguage().isEmpty()) { + list.add(String.format("%s_%s.properties", base, loc.getLanguage())); + } + list.add(path); + return list; + } + } diff --git a/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java b/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java index de5ba443d1..6a4374e6ee 100644 --- a/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java +++ b/impl/src/main/java/com/sun/faces/application/resource/WebappResourceHelper.java @@ -114,15 +114,21 @@ public String getBaseContractsPath() { return BASE_CONTRACTS_PATH; } - /** + /** * @see ResourceHelper#getNonCompressedInputStream(com.sun.faces.application.resource.ResourceInfo, * jakarta.faces.context.FacesContext) */ @Override protected InputStream getNonCompressedInputStream(ResourceInfo resource, FacesContext ctx) throws IOException { - - return ctx.getExternalContext().getResourceAsStream(resource.getPath()); - + List localizedPaths = getLocalizedPaths(resource.getPath(), ctx); + InputStream in = null; + for (String path_: localizedPaths) { + in = ctx.getExternalContext().getResourceAsStream(path_); + if (in != null) { + break; + } + } + return in; } /** @@ -289,5 +295,4 @@ private String findPathConsideringContracts(LibraryInfo library, String resource return basePath; } - }