Struts2: Return null/key if mapping doesn't found in locale specific resource file

63 views Asked by At

I want to check a key mapping in locale specific resource bundle files ONLY in complete hierarchy and don't want to fall back to default .properties file. Say I have resource bundle files Text_fr.properties and Text.properties and global_fr.properties and global.properties I want that if I search a key in language 'fr', it should check in *_fr.properties files only and if no mapping found then don't return me default *.properties file value rather give me null or key

I have tried running this code segment but it didn't met my requirnment

    if(null != LocalizedTextUtil.findDefaultText(key, getLocale())){
        return LocalizedTextUtil.findDefaultText(key, getLocale());
    }else{
         return defaultValue;
    }

I have tried other LocalizedTextUtil.findText(); variants too.

Say I have following content in files

+--------------------+-----------------+----------------------+-------------------+
| Text_fr.properties | Text.properties | global_fr.properties | global.properties |
+--------------------+-----------------+----------------------+-------------------+
| key.hi=Hi in fr    | key.hi=Hi in en | key.hi=fr            | key.hi=en         |
+--------------------+-----------------+----------------------+-------------------+

Now when I search key.hi with language fr I need to get strings Hi in fr or fr or if both mappings not found in *_fr.properties files I do not want it to return me either Hi in en or en rather just return me null or actual key.

0

There are 0 answers