Skip to content

Commit

Permalink
Version 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alaugks committed Sep 18, 2024
1 parent 4702d94 commit 1aa5e34
Show file tree
Hide file tree
Showing 75 changed files with 1,045 additions and 2,972 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ on:
push:
branches:
- main
- stage
- dev
- snapshot/*
- release/*
# pull_request:
# types: [opened, synchronize, reopened]
workflow_dispatch:
# workflow_dispatch:
jobs:
build:
name: Build and analyze
Expand Down Expand Up @@ -58,4 +54,4 @@ jobs:
-Dsonar.exclusions=${{ vars.SONAR_EXCLUSIONS }} \
-Dsonar.java.binaries=${{ vars.SONAR_JAVA_BINARIES }} \
-Dsonar.coverage.exclusions=${{ vars.SONAR_COVERAGE_EXCLUSIONS }} \
-Dsonar.java.source=${{ vars.SONAR_JAVA_SOURCE }}
-Dsonar.java.source=17
88 changes: 30 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This package provides a [MessageSource](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/MessageSource.html) for using translations from XLIFF files. The package support XLIFF versions 1.2, 2.0 and 2.1.

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=alaugks_spring-xliff-translation&metric=alert_status)](https://sonarcloud.io/summary/overall?id=alaugks_spring-xliff-translation)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.alaugks/spring-messagesource-xliff.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/io.github.alaugks/spring-messagesource-xliff/1.3.0)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.alaugks/spring-messagesource-xliff.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/io.github.alaugks/spring-messagesource-xliff/2.0.0)

## Dependency

Expand All @@ -12,59 +12,59 @@ This package provides a [MessageSource](https://docs.spring.io/spring-framework/
<dependency>
<groupId>io.github.alaugks</groupId>
<artifactId>spring-messagesource-xliff</artifactId>
<version>1.3.0</version>
<version>2.0.0</version>
</dependency>
```

### Gradle

```text
implementation group: 'io.github.alaugks', name: 'spring-messagesource-xliff', version: '1.3.0'
implementation group: 'io.github.alaugks', name: 'spring-messagesource-xliff', version: '2.0.0'
```

### Snapshots

| Version | Description |
|:---------------|:------------------------------------------------------------------------------------------|
| 2.0.0-SNAPSHOT | [SNAPSHOT](https://github.com/alaugks/spring-messagesource-xliff/tree/snapshot/2.0.0) | |


## MessageSource Configuration

The class XliffTranslationMessageSource implements the [MessageSource](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/MessageSource.html) interface.

### XliffTranslationMessageSource
`builder(Locale defaultLocale, String locationPattern)` or<br>
`builder(Locale defaultLocale, List<String> locationPatterns)` (***required***)
* Argument `Locale locale`: Defines the default locale.
* Argument `String locationPattern` | `List<String> locationPatterns`:
* Defines the pattern used to select the XLIFF files.
* The package uses the [PathMatchingResourcePatternResolver](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/io/support/PathMatchingResourcePatternResolver.html) to select the XLIFF files. So you can use the supported patterns.
* Files with the extension `xliff` and `xlf` are filtered from the result list.

`setBasenamePattern(String basename)` or `setBasenamesPattern(Iterable<String> basenames)` (***required***)
`defaultDomain(String defaultDomain)`

* Defines the pattern used to select the XLIFF files.
* The package uses the [PathMatchingResourcePatternResolver](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/io/support/PathMatchingResourcePatternResolver.html) to select the XLIFF files. So you can use the supported patterns.
* Files with the extension `xliff` and `xlf` are filtered from the result list.
* Defines the default domain. Default is `messages`. For more information, see [XlIFF Translations Files](#xliff-translation-files).

`setDefaultLocale(Locale locale)` (***required***)
* Defines the default language.

`setDefaultDomain(String defaultDomain)`
* Defines the default domain. Default is `messages`. For more information, see [XlIFF Translations Files](#xliff).
### Example

* Default locale is `en`.
* The Xliff files are stored in `src/main/resources/translations`.

```java
import de.alaugks.spring.XliffTranslationMessageSource;
import io.github.alaugks.spring.messagesource.xliff.XliffResourceMessageSource;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Locale;

@Configuration
public class MessageConfig {


@Bean
public MessageSource messageSource() {
XliffTranslationMessageSource messageSource = new XliffTranslationMessageSource();
messageSource.setDefaultLocale(Locale.forLanguageTag("en"));
messageSource.setBasenamePattern("translations/*");
return messageSource;
return XliffResourceMessageSource
.builder(
Locale.forLanguageTag("en"),
"translations/*"
)
.build();
}

}
```

Expand All @@ -77,10 +77,12 @@ public class MessageConfig {
* **XLIFF 1.2**:
* If the attribute `resname` does not exist, the attribute `id` is used to determine the identifier.
* Documentation identifier: [XLIFF 1.2](http://docs.oasis-open.org/xliff/v1.2/xliff-profile-html/xliff-profile-html-1.2.html#General_Identifiers)
* XLIFF 2.*:
* **XLIFF 2.&ast;**:
* The attribute `id` is optional by standard in XLIFF 2.*. However, this package requires the `id` on a translation unit.
* Documentation identifier: [XLIFF 2.0](https://docs.oasis-open.org/xliff/xliff-core/v2.0/csprd01/xliff-core-v2.0-csprd01.html#segment) and [XLIFF 2.1](https://docs.oasis-open.org/xliff/xliff-core/v2.1/os/xliff-core-v2.1-os.html#segment)
* For performance reasons, there is no validation of XLIFF files with an XMLSchema. If there is any corrupt XML in an XLIFF file, the SAX parser will throw a [Fatal Error].
* All attributes in the `<file/>` tag are ignored.
* For performance reasons, there is no validation of XLIFF files with an XMLSchema.
* SAX parser errors are handled by an [ErrorHandler](src/main/java/io/github/alaugks/spring/messagesource/xliff/exception/SaxErrorHandler.java).

### Structure of the Translation Filename

Expand Down Expand Up @@ -133,14 +135,6 @@ Mixing XLIFF versions is possible. Here is an example using XLIFF 1.2 and XLIFF
<source>Postcode</source>
<target>Postcode</target>
</trans-unit>
<trans-unit id="email-notice">
<source>Your email {0} has been registered.</source>
<target>Your email {0} has been registered.</target>
</trans-unit>
<trans-unit id="default-message">
<source>This is a default message.</source>
<target>This is a default message.</target>
</trans-unit>
</body>
</file>
</xliff>
Expand All @@ -163,14 +157,6 @@ Mixing XLIFF versions is possible. Here is an example using XLIFF 1.2 and XLIFF
<source>Postcode</source>
<target>Postleitzahl</target>
</trans-unit>
<trans-unit id="email-notice">
<source>Your email {0} has been registered.</source>
<target>Ihre E-Mail {0} wurde registriert.</target>
</trans-unit>
<trans-unit id="default-message">
<source>This is a default message.</source>
<target>Das ist ein Standardtext.</target>
</trans-unit>
</body>
</file>
</xliff>
Expand Down Expand Up @@ -282,20 +268,6 @@ The behaviour of resolving the target value based on the code is equivalent to t
<td>Postleitzahl</td>
<td>Postcode</td>
</tr>
<tr>
<td>email-notice*<br>messages.email-notice</td>
<td>Your email {0} has been registered.</td>
<td>Your email {0} has been registered.**</td>
<td>Ihre E-Mail {0} wurde registriert.</td>
<td>Your email {0} has been registered.</td>
</tr>
<tr>
<td>default-message*<br>messages.default-message</td>
<td>This is a default message.</td>
<td>This is a default message.**</td>
<td>Das ist ein Standardtext.</td>
<td>This is a default message.</td>
</tr>
<tr>
<td>payment.headline</td>
<td>Payment</td>
Expand Down
Loading

0 comments on commit 1aa5e34

Please sign in to comment.