Skip to content

Commit

Permalink
Align packages and improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Dec 22, 2012
1 parent 1594b39 commit a19723d
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 15 deletions.
75 changes: 75 additions & 0 deletions kitchensink-ml-ear/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,81 @@ This project is setup to allow you to create a _localized_ Java EE 6 compliant a

This quickstart uses the `kitchensink-ear` quickstart as its starting point. It has been enhanced to provide localization of labels and messages. A user sets the preferred language choice in the browser and, if the application supports that language, the application web page is rendered in that language. For demonstration purposes, this quickstart has been tranlated into French(fr) and Spanish (es) using <http://translate.google.com>, so the translations may not be ideal.

### Localization Code Changes

The following changes were made to the quickstart to enable it to use the browser preferred locale setting when displaying the web page:

* Properties files were created for the supported languages.

* This quickstart is localized for Spanish and French. You can add additional language support by creating properties files with the appropriate suffix and populating the properties with translated values.

* The JSF resource Bundle is located at `jboss-as-kitchensink-ml-ear-web/src/main/resources/org/jboss/as/quickstarts/kitchensink-ml/bundle/Resources_(es|fr).properties

* Messages generated by Java code (e.g. log messages and messages sent to the UI) are internationalized using JBoss Logging. The log messages are accessed via the `org.jboss.as.quickstarts.kitchensink.util.KitchensinkMessages` interface, and the message bundles are located at: `jboss-as-kitchensink-ml-ear-ejb/src/main/resources/org/jboss/as/quickstarts/kitchensink/util/KitchensinkMessages.i18_(es|fr).properties`

* The message bundle consumed by Bean Validation is located at `jboss-as-kitchensink-ml-ear-ejbsrc/main/resources/ValidationMessages.properties' (this is defined by the bean validation specification).

* The following XML was added to the `jboss-as-kitchensink-ml-ear-web/src/main/webapp/WEB-INF/faces-config.xml` file. When you create a property file for a new language, you must add the supported locale to this file.

<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>en-US</supported-locale>
<supported-locale>es</supported-locale>
<supported-locale>ES-FR</supported-locale>
<supported-locale>fr</supported-locale>
<supported-locale>fr-FR</supported-locale>
</locale-config>
<resource-bundle>
<base-name>org/jboss/as/quickstarts/kitchensink_ear/bundle/Resources</base-name>
<var>bundle</var>
</resource-bundle>
</application>
* The `jboss-as-kitchensink-ml-ear-ejb/src/main/java/org/jboss/as/quickstarts/kitchensink/model/Member.java` file was modififed to add the message key to @Pattern annotation.

@NotNull
@Size(min = 1, max = 25)
@Pattern(regexp = "[A-Za-z ]*", message = "{name_validation_message}")
private String name;

* The `jboss-as-kitchensink-ml-ear-ejb/src/main/java/org/jboss/as/quickstarts/kitchensink/util/KitchensinkMessages.java` file was created, which defines default messages in English. The `jboss-logging-processor` will automatically generate an implementation for you, which can be accesssed via the `MESSAGES` static variable.

@MessageBundle(projectCode = "")
public interface KitchensinkMessages {
KitchensinkMessages MESSAGES = Messages.getBundle(KitchensinkMessages.class, FacesContext.getCurrentInstance().getViewRoot().getLocale());
@Message("Registered!")
String registeredMessage();
@Message("Successfully registered!")
String registerSuccessfulMessage();
@Message("Registration failed:")
String registerFailMessage();
@Message("Registration failed. See server log for more information.")
String defaultErrorMessage();
}

* The `jboss-as-kitchensink-ml-ear-web/src/main/java/org/jboss/as/quickstarts/kitchensink/controller/MemberController.java` file was modified as follows:

* Messages strings were replaced with strings retrieved using the resource bundle property names. For example:

FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_INFO,
KitchensinkMessages.MESSAGES.registeredMessage(),
KitchensinkMessages.MESSAGES.registerSuccessfulMessage());

* The `jboss-as-kitchensink-ml-ear-web/src/main/webapp/index.xhtml` file were modified.

* Strings for headers, messages, labels were replaced with the appropriate `# {bundle.<property>}`, for example: `# {bundle.memberWelcomeHeader}`.

### Set the Browser Preferred Locale

How you set your browser preferred locale depends on the browser and version you use. Use your browser help option to search for instructions to change the preferred language setting.


System requirements
-------------------

Expand Down
2 changes: 1 addition & 1 deletion kitchensink-ml-ear/jboss-as-kitchensink-ml-ear-ejb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
</dependency>

<!-- Logging tooling is only needed for annotation processing at
compile time, no runtime depdenceny needed -->
compile time, no runtime dependency needed -->
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<supported-locale>es-ES</supported-locale>
</locale-config>
<resource-bundle>
<base-name>org/jboss/as/quickstarts/kitchensink-ml/bundle/Resources</base-name>
<base-name>org/jboss/as/quickstarts/kitchensink_ear/bundle/Resources</base-name>
<var>bundle</var>
</resource-bundle>
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
<f:loadBundle basename="org.jboss.as.quickstarts.kitchensink-ml.bundle.Resources" var="bundle" />
<h:head>
<title>kitchensink-ear</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" template="/WEB-INF/templates/default.xhtml">
<f:loadBundle basename="org.jboss.as.quickstarts.kitchensink-ml.bundle.Resources" var="bundle" />
<ui:define name="content">
<h1>#{bundle.memberWelcomeHeader}</h1>

Expand Down
14 changes: 5 additions & 9 deletions kitchensink-ml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@ The following changes were made to the quickstart to enable it to use the browse

* Properties files were created for the supported languages.

* They are located in the `src/main/resources/org/jboss/as/quickstarts/kitchensink-ml/bundle` directory.

* This quickstart is localized for Spanish and French. You can add additional language support by creating properties files with the appropriate suffix and populating the properties with translated values.

* The JSF resource Bundle is located at `src/main/resources/org/jboss/as/quickstarts/kitchensink-ml/bundle/Resources_(es|fr).properties
* The JSF resource Bundle is located at `src/main/resources/org/jboss/as/quickstarts/kitchensink/bundle/Resources_(es|fr).properties

* For JBoss Logging, the files has the same package and class name: `src/main/resources/org/jboss/as/quickstarts/kitchensink/util/KitchensinkMessages.i18_(es|fr).properties`
* Messages generated by Java code (e.g. log messages and messages sent to the UI) are internationalized using JBoss Logging. The log messages are accessed via the `org.jboss.as.quickstarts.kitchensink.util.KitchensinkMessages` interface, and the message bundles are located at: `src/main/resources/org/jboss/as/quickstarts/kitchensink/util/KitchensinkMessages.i18_(es|fr).properties`

For Beans Validation (JSR303), the new Properties file were created and it must call `ValidationMessages.properties'.

* They are located in the `src/main/resources/` directory
* The message bundle consumed by Bean Validation is located at `src/main/resources/ValidationMessages.properties' (this is defined by the bean validation specification).

* The following XML was added to the `src/main/webapp/WEB-INF/faces-config.xml` file. When you create a property file for a new language, you must add the supported locale to this file.

Expand All @@ -45,7 +41,7 @@ For Beans Validation (JSR303), the new Properties file were created and it must
<supported-locale>fr-FR</supported-locale>
</locale-config>
<resource-bundle>
<base-name>org/jboss/as/quickstarts/kitchensink-ml/bundle/Resources</base-name>
<base-name>org/jboss/as/quickstarts/kitchensink/bundle/Resources</base-name>
<var>bundle</var>
</resource-bundle>
</application>
Expand All @@ -57,7 +53,7 @@ For Beans Validation (JSR303), the new Properties file were created and it must
@Pattern(regexp = "[A-Za-z ]*", message = "{name_validation_message}")
private String name;

* The `src/main/java/org/jboss/as/quickstarts/kitchensink/util/KitchensinkMessages.java` file was created
* The `src/main/java/org/jboss/as/quickstarts/kitchensink/util/KitchensinkMessages.java` file was created, which defines default messages in English. The `jboss-logging-processor` will automatically generate an implementation for you, which can be accesssed via the `MESSAGES` static variable.

@MessageBundle(projectCode = "")
public interface KitchensinkMessages {
Expand Down
2 changes: 1 addition & 1 deletion kitchensink-ml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
</dependency>

<!-- Logging tooling is only needed for annotation processing at
compile time, no runtime depdenceny needed -->
compile time, no runtime dependency needed -->
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion kitchensink-ml/src/main/webapp/WEB-INF/faces-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<supported-locale>es-ES</supported-locale>
</locale-config>
<resource-bundle>
<base-name>org/jboss/as/quickstarts/kitchensink-ml/bundle/Resources</base-name>
<base-name>org/jboss/as/quickstarts/kitchensink/bundle/Resources</base-name>
<var>bundle</var>
</resource-bundle>
</application>
Expand Down

0 comments on commit a19723d

Please sign in to comment.