Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 87C0D200CB3 for ; Mon, 26 Jun 2017 18:28:23 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 86B6C160BDE; Mon, 26 Jun 2017 16:28:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CC8DD160BD9 for ; Mon, 26 Jun 2017 18:28:22 +0200 (CEST) Received: (qmail 11026 invoked by uid 500); 26 Jun 2017 16:28:22 -0000 Mailing-List: contact dev-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Developers List" Reply-To: "Struts Developers List" Delivered-To: mailing list dev@struts.apache.org Received: (qmail 11015 invoked by uid 99); 26 Jun 2017 16:28:21 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Jun 2017 16:28:21 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 5491C19202E for ; Mon, 26 Jun 2017 16:28:21 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.3 X-Spam-Level: X-Spam-Status: No, score=0.3 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id BAUXL1b-kYjy for ; Mon, 26 Jun 2017 16:28:18 +0000 (UTC) Received: from mxout014.mail.hostpoint.ch (mxout014.mail.hostpoint.ch [217.26.49.174]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 8AC735F6C8 for ; Mon, 26 Jun 2017 16:28:18 +0000 (UTC) Received: from [10.0.2.46] (helo=asmtp013.mail.hostpoint.ch) by mxout014.mail.hostpoint.ch with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1dPWry-0000ml-PY for dev@struts.apache.org; Mon, 26 Jun 2017 18:28:10 +0200 Received: from [2a02:120b:c3d8:56e0:a518:1928:4e18:8c2b] by asmtp013.mail.hostpoint.ch with esmtpa (Exim 4.89 (FreeBSD)) (envelope-from ) id 1dPWry-000KVw-N8 for dev@struts.apache.org; Mon, 26 Jun 2017 18:28:10 +0200 X-Authenticated-Sender-Id: info@flyingfischer.ch Subject: Re: Struts 2.5.11 test build is ready To: dev@struts.apache.org References: <5aa42f46-703b-a55a-e4a8-e075fb088a2f@flyingfischer.ch> From: "info@flyingfischer.ch" Message-ID: Date: Mon, 26 Jun 2017 18:28:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: de-CH archived-at: Mon, 26 Jun 2017 16:28:23 -0000 Am 26.06.2017 um 08:57 schrieb Lukasz Lenart: > 2017-06-25 8:07 GMT+02:00 info@flyingfischer.ch : >> I get stuck with the refactored LocalizedTextUtil: >> >> We had a change in 2.5.2 which disallowed the use of getText(String key) >> in classes that cannot extend ActionSupport. >> >> I did work around with a custom utility class that did the job, built >> mainly around: >> >> final String value = LocalizedTextUtil.findDefaultText(key, getLocale()); >> >> This does not work anymore. What is the present correct way to get this >> working? Is there any documentation for this? > LocalizedTextUtil was converted into a bean, the LocalizedTextProvider > - an interface with two implementations. You can use them by defining > a setter and annotating it with @Inject (like for other Struts beans) > > @Inject > public void setLocalizedTextProvider(LocalizedTextProvider > localizedTextProvider) { > this.localizedTextProvider = localizedTextProvider; > } > > This will inject an implementation which behaves the same as > LocalizedTextUtil, it will scan hierarchy (but just once) to localise > proper resource bundles. > > The second implementation based just on the global properties defined > with "struts.custom.i18n.resources" and you can use it by adding a > name to the @Inject > > @Inject("global-only") > public void setLocalizedTextProvider(LocalizedTextProvider > localizedTextProvider) { > this.localizedTextProvider = localizedTextProvider; > } > > > Regards Thanks for the inputs. I cant't get this to work. Sorry, this is rather a topic for user list. I'll wait to see some examples coming around. For the moment being I'll use, not very sophisticated my utility class below. This works fine. Though I think Struts should have somthing like this integrated. Before 2.5 this was as easy as "getText(key)". Markus package util; import java.util.Locale; import java.util.ResourceBundle; import org.apache.commons.text.StringEscapeUtils; import com.opensymphony.xwork2.ActionContext; public class Texti18n { /** * Returns i18n text messages from the default bundles for utility classes which cannot * extend ActionSupport: Utility myUtility = new Utility() will not work with struts default * getText() i18n mechanism, due to a change in behavior with struts > 2.5.2. * Returns the value for a key depending on the locale present. For missing i18n keys in a given * language bundle, the default bundle (English) will be used. If a key is not present at all, the key will * be returned instead of a value. */ public String getText(final String key) { final ResourceBundle bundle = ResourceBundle.getBundle("global-messages", getLocale()); final String value = bundle.getString(key); if (value != null) { return StringEscapeUtils.unescapeHtml4(value.replaceAll("''", "'")); } return key; } /** * Returns the Locale present in the ActionContext. The Locale.US will be returned as default, * if no Locale is present. */ public Locale getLocale() { final ActionContext context = ActionContext.getContext(); if (context != null && context.getLocale() != null) { return context.getLocale(); } else { // default language return Locale.US; } } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org For additional commands, e-mail: dev-help@struts.apache.org