Commit 77ef30a94f76590aac14dc8097c63715bc872c60
1 parent
174e15f0
Exists in
master
IN PROGRESS - issue FWK-93: Definir resource bundle através da
informação de idioma do navegador (HTTP header language) https://demoiselle.atlassian.net/browse/FWK-93
Showing
5 changed files
with
50 additions
and
7 deletions
Show diff stats
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/css/styles.css
0 → 100644
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +@CHARSET "UTF-8"; | |
| 2 | + | |
| 3 | +.ui-icon-locale-pt | |
| 4 | + ,.ui-icon-locale-en{ | |
| 5 | + width: 32px; | |
| 6 | + height: 31px; | |
| 7 | + background-position: center; | |
| 8 | + display: block; | |
| 9 | + float: left; | |
| 10 | + background-repeat: no-repeat; | |
| 11 | +} | |
| 12 | + | |
| 13 | +.ui-icon-locale-pt{ | |
| 14 | + background-image: url("../images/locale_pt.png"); | |
| 15 | +} | |
| 16 | + | |
| 17 | +.ui-icon-locale-en{ | |
| 18 | + background-image: url("../images/locale_en.png"); | |
| 19 | +} | |
| 0 | 20 | \ No newline at end of file | ... | ... |
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/images/locale_en.png
0 → 100644
1.95 KB
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/images/locale_pt.png
0 → 100644
2.16 KB
archetype/jsf-jpa/src/main/resources/archetype-resources/src/main/webapp/template/main.xhtml
| 1 | 1 | <html xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" |
| 2 | 2 | xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"> |
| 3 | 3 | |
| 4 | -<f:view contentType="text/html" /> | |
| 4 | +<f:view contentType="text/html" locale="#{locales.currentLocale}" /> | |
| 5 | 5 | |
| 6 | 6 | <h:head> |
| 7 | 7 | <title>#{messages['main.app.title']}</title> |
| ... | ... | @@ -11,7 +11,19 @@ |
| 11 | 11 | <h:body style="background-color:#f1f1f1"> |
| 12 | 12 | <table style="width: 100%"> |
| 13 | 13 | <tr> |
| 14 | - <td height="70" align="left"><a href="index.jsf"><img src="images/logo.png" border="0" /></a></td> | |
| 14 | + <td height="70" align="left"> | |
| 15 | + <a href="index.jsf"><img src="images/logo.png" border="0" /></a> | |
| 16 | + <div style="float: right;"> | |
| 17 | + <h:form id="language_form" prependId="true"> | |
| 18 | + <h:commandLink action="#{locales.setCurrentLocale('pt')}"> | |
| 19 | + <span class="ui-icon-locale-pt" ></span> | |
| 20 | + </h:commandLink> | |
| 21 | + <h:commandLink action="#{locales.setCurrentLocale('en')}"> | |
| 22 | + <span class="ui-icon-locale-en" ></span> | |
| 23 | + </h:commandLink> | |
| 24 | + </h:form> | |
| 25 | + </div> | |
| 26 | + </td> | |
| 15 | 27 | </tr> |
| 16 | 28 | <tr> |
| 17 | 29 | <td height="20"><ui:include src="/menu.xhtml" /></td> | ... | ... |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/Locales.java
| ... | ... | @@ -67,20 +67,20 @@ public class Locales implements Serializable { |
| 67 | 67 | * Set the language to "en_US". This is a shorthand to <code>setLocale(Locale.US)</code>. |
| 68 | 68 | */ |
| 69 | 69 | public void setEnglish() { |
| 70 | - setLocale(Locale.US); | |
| 70 | + setCurrentLocale(Locale.US); | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * Set the language to "pt_BR". This is a shorthand to <code>setLocale(Locales.PT_BR)</code>. |
| 75 | 75 | */ |
| 76 | 76 | public void setPortuguese() { |
| 77 | - setLocale(PT_BR); | |
| 77 | + setCurrentLocale(PT_BR); | |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * @return The current locale, or {@link Locale#getDefault()} if one has not been set. |
| 82 | 82 | */ |
| 83 | - public Locale getLocale(){ | |
| 83 | + public Locale getCurrentLocale(){ | |
| 84 | 84 | return this.locale!=null ? this.locale : Locale.getDefault(); |
| 85 | 85 | } |
| 86 | 86 | |
| ... | ... | @@ -89,7 +89,7 @@ public class Locales implements Serializable { |
| 89 | 89 | * |
| 90 | 90 | * @param locale The new locale |
| 91 | 91 | */ |
| 92 | - public void setLocale(Locale locale) { | |
| 92 | + public void setCurrentLocale(Locale locale) { | |
| 93 | 93 | Iterator<Locale> supportedLocales = getContext().getApplication().getSupportedLocales(); |
| 94 | 94 | if (supportedLocales==null){ |
| 95 | 95 | this.locale = locale; |
| ... | ... | @@ -114,6 +114,18 @@ public class Locales implements Serializable { |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | + * Set the locale for the current view. The language will be parsed | |
| 118 | + * into an instance of {@link Locale} and then {@link #setLocale(Locale locale)} will | |
| 119 | + * be called using the parsed language. | |
| 120 | + * | |
| 121 | + * @param language String language code that will be parsed into a locale. | |
| 122 | + */ | |
| 123 | + public void setCurrentLocale(String language){ | |
| 124 | + Locale locale = new Locale(language); | |
| 125 | + setCurrentLocale(locale); | |
| 126 | + } | |
| 127 | + | |
| 128 | + /** | |
| 117 | 129 | * Set the default locale for the entire application. After this call |
| 118 | 130 | * all views from this application will use this locale (unless a specific |
| 119 | 131 | * session defined a different locale using {@link #setLocale(Locale locale)}). |
| ... | ... | @@ -121,7 +133,7 @@ public class Locales implements Serializable { |
| 121 | 133 | * @param locale The locale to set |
| 122 | 134 | */ |
| 123 | 135 | public void setApplicationLocale(Locale locale) { |
| 124 | - setLocale(locale); | |
| 136 | + setCurrentLocale(locale); | |
| 125 | 137 | getContext().getApplication().setDefaultLocale(this.locale); |
| 126 | 138 | } |
| 127 | 139 | ... | ... |