You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by me...@apache.org on 2022/11/16 12:28:56 UTC
[myfaces] branch main updated: Fixing localized composite behaviour (main) (#369)
This is an automated email from the ASF dual-hosted git repository.
melloware pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/main by this push:
new 2445f1d72 Fixing localized composite behaviour (main) (#369)
2445f1d72 is described below
commit 2445f1d723c6dfeae0ddf072fdd993b65040f35a
Author: Paulo Cristovão de Araújo Silva Filho <pc...@gmail.com>
AuthorDate: Wed Nov 16 09:28:51 2022 -0300
Fixing localized composite behaviour (main) (#369)
* [localized-composite] Fixing localized composite properties loading
* [localized-composite-main] Fixed style
---
.../java/jakarta/faces/component/UIComponent.java | 51 ++++++++++++++++++++--
1 file changed, 48 insertions(+), 3 deletions(-)
diff --git a/api/src/main/java/jakarta/faces/component/UIComponent.java b/api/src/main/java/jakarta/faces/component/UIComponent.java
index 47be4d736..e40e93e9f 100755
--- a/api/src/main/java/jakarta/faces/component/UIComponent.java
+++ b/api/src/main/java/jakarta/faces/component/UIComponent.java
@@ -573,9 +573,8 @@ public abstract class UIComponent
// Call ResourceHandler.createResource(java.lang.String,java.lang.String), passing the derived
// resourceName and
// libraryName.
- Resource bundleResource = context.getApplication().getResourceHandler()
- .createResource(resourceName, componentResource.getLibraryName());
-
+ Resource bundleResource = getLocalizedCompositeResource(resourceName, componentResource.getLibraryName(), context);
+
if (bundleResource != null)
{
// If the resultant Resource exists and can be found, the InputStream for the resource
@@ -1091,4 +1090,50 @@ public abstract class UIComponent
void setCachedFacesContext(FacesContext facesContext)
{
}
+
+ private Resource getLocalizedCompositeResource(String resourceName, String libraryName, FacesContext context)
+ {
+ List<String> localizedPaths = getLocalizedPropertiesPaths(resourceName, context);
+ Resource resource = null;
+ for (String localizedPath: localizedPaths)
+ {
+ resource = context.getApplication().getResourceHandler().createResource(localizedPath, libraryName);
+ if (resource != null)
+ {
+ break;
+ }
+ }
+
+ return resource;
+ }
+
+ private List<String> getLocalizedPropertiesPaths(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<String> 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;
+ }
}