Skip to content

Commit

Permalink
Merge branch 'master' into SHIBUI-808
Browse files Browse the repository at this point in the history
  • Loading branch information
jj committed Oct 9, 2018
2 parents a81a2dc + 6ca0465 commit 0104cd8
Show file tree
Hide file tree
Showing 54 changed files with 1,331 additions and 454 deletions.
42 changes: 30 additions & 12 deletions INTERNATIONALIZATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,29 @@

## About

The Shibboleth UI leverages Angular's built in internationalization (i18n)
system feature to allow for localization of the views.
The Shibboleth UI leverages the messages_*_*.properties files common to Java/Spring applications. The default files are located in `backend > src > main > resources > i18n`.

<https://angular.io/guide/i18n>
This will allow any piece of static text in the application to be modified dynamically.

Angular allows any piece of text in an HTML template to be included in the
translation source file.
## Usage

In the UI code, there are three options for converting the text provided into translated text.

* Component: `<translate-i18n key="action.foo">Foo</translate-i18n>`
* Directive: `<label for="foo" translate="label.foo">Foo</label>`
* Pipe: `{{ action.foo | translate }}`

In addition, the `application.yml` file is an example of a file where dynamic values from the server, can be populated with an i18n identifier for translation. The json files used to generate the metadata wizards also make use of these identifiers and can be translated. They all use the same `messages.properties` files.

Here is an example of the identifers and text found in the `messages.properties` files.

```
action.cancel=Cancel
action.save=Save
action.delete-type=Delete { type }
```

The `action.delete-type=Delete { type }` example shows how dynamic text can be inserted into the translation as well. These values are determined by the application and are populated at runtime based on user interaction. Many of these values can be translated separately.

## Conventions

Expand All @@ -18,15 +34,15 @@ To allow for easier identification of relevant strings the identifiers are
provided in the following format

```
type--kebab-case-text
type.kebab-case-text
```

For example

```html
<button>example text</button>
<!-- would become -->
<button i18n="@@action--example-text">example text</button>
<button translate="action.example-text">example text</button>
```

Where `type` is one of the provided types listed in [the types section](#types)
Expand All @@ -42,15 +58,17 @@ The following types are provided:

* `action` buttons or links that cause a state change within the app
* `label` label for an input or a section
* `warning` messages that warn a user of exceptions in interactions, i.e.
* `message` messages that warn a user of exceptions in interactions, i.e.
validation messages
* `value` text for displaying values such as `true` or `false`
* `branding.*` this special type is used to denote the customizable values located in the `ui > brand.ts` file

### Localize Text Only

```html
<!-- BAD -->
<!-- this will pull both the text AND the icon into the translation -->
<button i18n="@@action--some-text">
<button i18n="action.some-text">
some text
<i class="fa fa-icon"></i>
</span>
Expand All @@ -59,7 +77,7 @@ The following types are provided:
<!-- this will only localize the text -->
<!-- NOTE: ng-container does not create any new dom on the page -->
<button>
<ng-container i18n="@@action--some-text">some text</ng-container>
<translate key="action.some-text">some text</ng-container>
<i class="fa fa-icon"></i>
</button>
```
Expand All @@ -71,9 +89,9 @@ When updating text, update the identifier to match the new text field.
```html
<!-- BAD -->
<!-- identifier does not match text after update -->
<label i18n="@@label--name">Address</label>
<label translate="label.name">Address</label>

<!-- GOOD -->
<!-- identifier and text match -->
<label i18n="@@label--address">Address</label>
<label translate="label.address">Address</label>
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ public class InternationalizationConfiguration {
public LocaleResolver localeResolver() {
// TODO if we want to control the order, we can implement our own locale resolver instead of using the SessionLocaleResolver.
SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();

// NOTE: If we set a default here, Locale.getDefault's behavior will be consistent, but then Accept-Language
// is not honored (only ?lang=). If we do not set a default, the default is determined at runtime by the JVM.
// This may break unit tests if the system does not determine the default to be English.
// sessionLocaleResolver.setDefaultLocale(new Locale("en"));

return sessionLocaleResolver;
}

@Bean
public MappedResourceBundleMessageSource messageSource() {
MappedResourceBundleMessageSource source = new MappedResourceBundleMessageSource();
source.setBasenames("i18n/messages");
source.setUseCodeAsDefaultMessage(true);
source.setUseCodeAsDefaultMessage(false); //TODO Why was this true?
source.setFallbackToSystemLocale(false); // allows us to return messages.properties instead of
// messages_en.properties for unsupported languages.
return source;
}
}
Loading

0 comments on commit 0104cd8

Please sign in to comment.