You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by infiniter <in...@gmail.com> on 2012/03/17 01:24:33 UTC

support for L10N in templates

There is already localization and styles support for resource references, but
I haven't seen that type of support for in text templates. Any ideas on how
it can be implemented??

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/support-for-L10N-in-templates-tp4479741p4479741.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: support for L10N in templates

Posted by Martin Grigorov <mg...@apache.org>.
Create a ticket about this.
With a patch will be even better!

On Wed, Mar 21, 2012 at 12:55 AM, infiniter <in...@gmail.com> wrote:
> I can't use that TextTemplateResourceReference 'cause the style and locale
> are set to null by default in the constructors and the filename passed to
> PackagedTextTemplate is exactly the one passed in the constructor.
> See:
> public TextTemplateResourceReference(final Class<?> scope, final String
> fileName,
>        final String contentType, final String encoding, IModel<Map&lt;String,
> Object>> variablesModel) {
>        super(scope, fileName); //STYLE AND LOCALE ARE NULL
>
>        textTemplate = new PackagedTextTemplate(scope, fileName, contentType,
> encoding);
>        this.variablesModel = variablesModel;
> }
>
> i guess I'll have to implement that filename-solving part "manually" by
> creating my own PackagedTextTemplate and changing the constructor where that
> logic happens.
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/support-for-L10N-in-templates-tp4479741p4490640.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: support for L10N in templates

Posted by infiniter <in...@gmail.com>.
I can't use that TextTemplateResourceReference 'cause the style and locale
are set to null by default in the constructors and the filename passed to
PackagedTextTemplate is exactly the one passed in the constructor.
See:
public TextTemplateResourceReference(final Class<?> scope, final String
fileName,
	final String contentType, final String encoding, IModel<Map&lt;String,
Object>> variablesModel) {
	super(scope, fileName); //STYLE AND LOCALE ARE NULL

	textTemplate = new PackagedTextTemplate(scope, fileName, contentType,
encoding);
	this.variablesModel = variablesModel;
}

i guess I'll have to implement that filename-solving part "manually" by
creating my own PackagedTextTemplate and changing the constructor where that
logic happens.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/support-for-L10N-in-templates-tp4479741p4490640.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: support for L10N in templates

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

See org.apache.wicket.resource.TextTemplateResourceReference.

On Mon, Mar 19, 2012 at 7:09 PM, infiniter <in...@gmail.com> wrote:
> Hi Martin,
> for more context what I need is "full" localization support for js
> templates, similar to the support provided for components:
> 1- by allowing to have localized js template files per page. E.g.: my.js,
> my_es.js, my_fr.js
> 2- by automatically solving messages in the template (without passing a
> variables model with all the messages). E.g.: var x =
> '${message:someResourceKey}';
>
> I already solved the 2nd one by overriding PackagedTextTemplate#asString()
> and overriding MapVariableInterpolator#getValue(). but now I need to
> localize the template file names themselves as mentioned in point 1.
>
> Thanx!
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/support-for-L10N-in-templates-tp4479741p4485558.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: support for L10N in templates

Posted by infiniter <in...@gmail.com>.
Hi Martin,
for more context what I need is "full" localization support for js
templates, similar to the support provided for components:
1- by allowing to have localized js template files per page. E.g.: my.js,
my_es.js, my_fr.js
2- by automatically solving messages in the template (without passing a
variables model with all the messages). E.g.: var x =
'${message:someResourceKey}';

I already solved the 2nd one by overriding PackagedTextTemplate#asString()
and overriding MapVariableInterpolator#getValue(). but now I need to
localize the template file names themselves as mentioned in point 1.

Thanx!

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/support-for-L10N-in-templates-tp4479741p4485558.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: support for L10N in templates

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

A template is a resource with placeholders. You need to interpolate
its content before serving it to the client.

In the example:
response.renderJavascriptReference(new ResourceReference(MyPage.class,
"my.js", getLocale(), getStyle()));

locale and style are used to load the most specific resource, e.g.
my_en_GB_green.js, where 'green' is a style.
Neither locale nor style are used to manipulate the content of that resource.

To do what you need :
Map<String, String> vars = new HashMap<String, String>() {
  @Override
  public String get(String resourceKey) {
   return MyComponent.this.getString(resourceKey); // or any other
variant of this method (overload)
  }
}

interpolatedTextTemplate = textTemplate.interpolate(vars);
response.renderJavaScript(interpolatedTextTemplate)

On Mon, Mar 19, 2012 at 4:15 AM, Bertrand Guay-Paquet
<be...@step.polymtl.ca> wrote:
> Yeah I threw that out there in case it also applied to templates. I don't
> know anything about them in Wicket...
>
>
> On 18/03/2012 8:19 PM, infiniter wrote:
>>
>> Oh no.
>> What I need is to be able to support something like the following, but for
>> TEMPLATES, 'cause I want to localize them:
>>  public void renderHead(IHeaderResponse response) {
>>         response.renderJavascriptReference(new ResourceReference(
>>         MyPage.class, "my.js", getLocale(), getStyle()));
>>     }
>>
>> anyone?
>>
>> --
>> View this message in context:
>> http://apache-wicket.1842946.n4.nabble.com/support-for-L10N-in-templates-tp4479741p4483475.html
>> Sent from the Users forum mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: support for L10N in templates

Posted by Bertrand Guay-Paquet <be...@step.polymtl.ca>.
Yeah I threw that out there in case it also applied to templates. I 
don't know anything about them in Wicket...

On 18/03/2012 8:19 PM, infiniter wrote:
> Oh no.
> What I need is to be able to support something like the following, but for
> TEMPLATES, 'cause I want to localize them:
>   public void renderHead(IHeaderResponse response) {
>          response.renderJavascriptReference(new ResourceReference(
>          MyPage.class, "my.js", getLocale(), getStyle()));
>      }
>
> anyone?
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/support-for-L10N-in-templates-tp4479741p4483475.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: support for L10N in templates

Posted by infiniter <in...@gmail.com>.
Oh no. 
What I need is to be able to support something like the following, but for
TEMPLATES, 'cause I want to localize them:
 public void renderHead(IHeaderResponse response) {
        response.renderJavascriptReference(new ResourceReference(
        MyPage.class, "my.js", getLocale(), getStyle()));
    }

anyone?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/support-for-L10N-in-templates-tp4479741p4483475.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: support for L10N in templates

Posted by Bertrand Guay-Paquet <be...@step.polymtl.ca>.
What is it you are trying to do?

In the html files, you can put <wicket:message> tags to have wicket 
automatically replace the contents with a localized message.

Example:

<wicket:message 
key="MyLocalizedMessageKey">MyLocalizedMessage</wicket:message>

with a properties file containing:
MyLocalizedMessageKey = Hi Infiniter!

Is this what you need?

On 16/03/2012 8:24 PM, infiniter wrote:
> There is already localization and styles support for resource references, but
> I haven't seen that type of support for in text templates. Any ideas on how
> it can be implemented??
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/support-for-L10N-in-templates-tp4479741p4479741.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org