01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.examples.pub;
18:
19: import java.util.Locale;
20:
21: import org.apache.wicket.PageParameters;
22: import org.apache.wicket.examples.WicketExamplePage;
23: import org.apache.wicket.markup.html.basic.Label;
24: import org.apache.wicket.markup.html.image.Image;
25: import org.apache.wicket.markup.html.link.Link;
26: import org.apache.wicket.model.Model;
27: import org.apache.wicket.model.StringResourceModel;
28: import org.apache.wicket.util.value.ValueMap;
29:
30: /**
31: * Demonstrates localization.
32: *
33: * @author Jonathan Locke
34: * @author Eelco Hillenius
35: */
36: public final class Home extends WicketExamplePage {
37: /**
38: * Constructor
39: *
40: * @param parameters
41: * Page parameters (ignored since this is the home page)
42: */
43: public Home(final PageParameters parameters) {
44: add(new Image("beer"));
45:
46: // create a dummy object to serve as our substitution model
47: ValueMap map = new ValueMap();
48: map.put("user", "Jonathan");
49:
50: // Here, we create a model that knows how to get localized strings.
51: // It uses the page's resource (Home_cc_LC.properties) and gets the
52: // text with resource key 'salution'. For the US, this is:
53: // salutation=${user}, dude!
54: // variable ${user} will be regconized as a property variable, and will
55: // be substituted with the given model (the wrapped map). Hence,
56: // ${user} will be replaced by map.get('user'), which is 'Jonathan'.
57: StringResourceModel labelModel = new StringResourceModel(
58: "salutation", this , new Model(map));
59:
60: // Add the label with the dynamic model
61: add(new Label("salutation", labelModel));
62:
63: // Add a couple of links to be able to play around with the session
64: // locale
65: add(new Link("goCanadian") {
66: public void onClick() {
67: getSession().setLocale(Locale.CANADA);
68: }
69: });
70: add(new Link("goUS") {
71: public void onClick() {
72: getSession().setLocale(Locale.US);
73: }
74: });
75: add(new Link("goDutch") {
76: public void onClick() {
77: getSession().setLocale(new Locale("nl", "NL"));
78: }
79: });
80: add(new Link("goGerman") {
81: public void onClick() {
82: getSession().setLocale(new Locale("de", "DE"));
83: }
84: });
85: add(new Link("goChinese") {
86: public void onClick() {
87: getSession().setLocale(new Locale("zh", "CN"));
88: }
89: });
90: add(new Link("goDanish") {
91: public void onClick() {
92: getSession().setLocale(new Locale("da", "DK"));
93: }
94: });
95: }
96: }
|