Miklós Győrfi created CAUSEWAY-4003:
---------------------------------------

             Summary: TitleColumn hardcodes English labels instead of using 
TranslationService for i18n in Wicket Viewer
                 Key: CAUSEWAY-4003
                 URL: https://issues.apache.org/jira/browse/CAUSEWAY-4003
             Project: Causeway
          Issue Type: Improvement
          Components: Viewer Wicket
    Affects Versions: 4.0.0-M1
            Reporter: Miklós Győrfi


In the Apache Causeway Wicket Viewer component, the {{TitleColumn}} (used to 
display the first/primary title column in parented and standalone collections 
inside {{{}CollectionContentsAsAjaxTablePanel, etc.{}}}) hardcodes the column 
headers as English text strings ("Object" and "Related Object").

Because this is evaluated via a static helper method during constructor 
invocation, it bypasses the framework's translation mechanisms, making it 
impossible to localize these headers via standard {{translations.po}} files.

*Affected Class:*
org.apache.causeway.viewer.wicket.ui.components.collection.present.ajaxtable.columns.TitleColumn

*Current problematic code snippet:*Java
 
{code:java}
private static String columnName(
        final @Nullable Variant variant,
        final int maxTitleLength) {
    if(maxTitleLength == 0) {
        return "";
    }
    return (variant.isParented() ? "Related ":"") + "Object"; // <-- Hardcoded 
English Strings
}
{code}
 

*Proposed Solution / Fix:*

The {{columnName}} method should dynamically resolve the text using Causeway's 
{{TranslationService}} fetched from the {{MetaModelContext}} to allow proper 
localization.
{code:java}
private static String columnName(
            final @Nullable Variant variant,
            final int maxTitleLength) {
        if(maxTitleLength == 0) {
            return "";
        }

        String defaultLabel = "Object";
        String contextClass = TitleColumn.class.getName();

        var mmc = MetaModelContext.instanceNullable();
        if (mmc != null) {
            TranslationService translationService = mmc.getTranslationService();
            if (translationService != null) {
                var translationContext = TranslationContext.named(contextClass);

                if (variant != null && variant.isParented()) {
                    return translationService.translate(translationContext, 
"Related Object");
                } else {
                    return translationService.translate(translationContext, 
"Object");
                }
            }
        }

        return (variant != null && variant.isParented() ? "Related " : "") + 
defaultLabel;    
    }
{code}
 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to