留言板

enhance LanguageUtil

Joerg Schaefer,修改在7 年前。

enhance LanguageUtil

New Member 帖子: 12 加入日期: 14-10-21 最近的帖子
Hi,
normally i use the LanguageUtil to retrieve only one string from a message bundle.

LanguageUtil.get(locale, key)...


Now i have the requirement to get more than one string back, because i used a prefix in my message bundles.
Something linke:
module1.label1=hello
module1.label2=test
moduel1.label3=mail
...

I need now to the extend the LanguageUtil in a way that it returns a map or something similar containing all prefixed data from the messeage bundle.
LanguageUtil.get(locale, prefixKey)


Does somebody know how i can achive this?

thanks Jörg
thumbnail
Andrew Jardine,修改在7 年前。

RE: enhance LanguageUtil

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Hi Joerg,

Why don't you just write your own wrapper and then use it in your implementations. Something like (and I'm freehanding here emoticon) --

public class CustomLanguageUtil extends LanguageUtil{

   public static String get(locale, key, prefixKey) {
      return get(locale, prefixKey+key);
   }
}


If you really want to augment the LanguageUtil class, I fear you may be stuck with an EXT plugin (gross). Personally I would opt for the wrapper.
thumbnail
Olaf Kock,修改在7 年前。

RE: enhance LanguageUtil

Liferay Legend 帖子: 6403 加入日期: 08-9-23 最近的帖子
Andrew Jardine:
If you really want to augment the LanguageUtil class, I fear you may be stuck with an EXT plugin (gross). Personally I would opt for the wrapper.


Thanks for the clarification sentence, Andrew. @Joerg: Don't add methods to the interface. This will break every other plugin that won't recognize the new interface of LanguageUtil. It's fine to introduce custom classes though, and they don't even need to be in Liferay's core - they can be local to the plugin.
thumbnail
Andrew Jardine,修改在7 年前。

RE: enhance LanguageUtil

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Hey Olaf,

I checked a few of my projects and that's pretty much exactly what I have done in the past. I have a maven module that builds to a common jar. In this jar I have a XXXLanguageUtil -- in fact, mine doesn't even extend, I just reference the LanguageUtil class in the methods where I need it. I have this common jar as a dependency in the projects where I need the extra push. All works like a charm emoticon. Long live the wrapper.
thumbnail
Olaf Kock,修改在7 年前。

RE: enhance LanguageUtil

Liferay Legend 帖子: 6403 加入日期: 08-9-23 最近的帖子
Andrew Jardine:
... I just reference the LanguageUtil class in the methods where I need it. I have this common jar as a dependency in the projects where I need the extra push. All works like a charm emoticon. Long live the wrapper.


Correct answer. ;) \o/