Skip to content

Commit

Permalink
Merge release/1.1.2 into main
Browse files Browse the repository at this point in the history
- Some internal code improvements
- Fixes Readme.de
  • Loading branch information
alaugks committed Jan 28, 2024
2 parents 9715d28 + ddb10e3 commit 74799c9
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 66 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/maven-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ on:
- stage
- dev
- feature/*
- release/*
# workflow_dispatch:
jobs:
tests:
name: Run tests
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-package: 'jdk'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ossrh-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-package: 'jdk'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY }} # -Dsonar.projectKey=$SONAR_PROJECTKEY
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v7
- name: Set up JDK 11
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu'
- name: Cache SonarCloud packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ This package provides a **MessageSource** for using translations from XLIFF file

| Version | Description |
|:--------|:------------------------------------------------------------------------------------------|
| 1.1.2 | [Release notes](https://github.com/alaugks/spring-messagesource-xliff/releases/tag/1.1.2) |
| 1.1.1 | [Release notes](https://github.com/alaugks/spring-messagesource-xliff/releases/tag/1.1.1) |
| 1.1.0 | [Release notes](https://github.com/alaugks/spring-messagesource-xliff/releases/tag/1.1.0) |
| 1.0.0 | First public version |


[![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.1.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.1.2)


<a name="a2"></a>
Expand All @@ -38,13 +39,13 @@ This package provides a **MessageSource** for using translations from XLIFF file
<dependency>
<groupId>io.github.alaugks</groupId>
<artifactId>spring-messagesource-xliff</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
</dependency>
```

**Gradle**
```text
implementation group: 'io.github.alaugks', name: 'spring-messagesource-xliff', version: '1.1.1'
implementation group: 'io.github.alaugks', name: 'spring-messagesource-xliff', version: '1.1.2'
```


Expand Down Expand Up @@ -420,13 +421,13 @@ Mixing XLIFF versions is possible. Here is an example using XLIFF 1.2 and XLIFF
| messages.headline | Headline | Überschrift | Headline** |
| postcode* | Postcode | Postleitzahl | Zip code |
| messages.postcode | Postcode | Postleitzahl | Zip code |
| headline-examples | Examples | Beispiele | Examples** |
| headline-examples* | Examples | Beispiele | Examples** |
| messages.headline-examples | Examples | Beispiele | Examples** |
| translation-args-label | Translation with param | Übersetzung mit Parameter | Translation with param** |
| translation-args-label* | Translation with param | Übersetzung mit Parameter | Translation with param** |
| messages.translation-args-label | Translation with param | Übersetzung mit Parameter | Translation with param** |
| email-notice | Your email {0} has been registered. | Ihre E-Mail {0} wurde registriert. | Your email {0} has been registered.** |
| email-notice* | Your email {0} has been registered. | Ihre E-Mail {0} wurde registriert. | Your email {0} has been registered.** |
| messages.email-notice | Your email {0} has been registered. | Ihre E-Mail {0} wurde registriert. | Your email {0} has been registered.** |
| default-message | This is a default message. | Das ist ein Standardtext. | This is a default message.** |
| default-message* | This is a default message. | Das ist ein Standardtext. | This is a default message.** |
| messages.default-message | This is a default message. | Das ist ein Standardtext. | This is a default message.** |
| payment.headline | Payment | Zahlung | Payment |
| payment.expiry_date | Expiry date | Ablaufdatum | Expiration date |
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: '3.6'
services:
spring-boot-xliff-example:
image: alaugks/spring-boot-xliff-example:1.1.0
image: alaugks/spring-boot-xliff-example:1.1.2
ports:
- 8080:8080
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.github.alaugks</groupId>
<artifactId>spring-messagesource-xliff</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand All @@ -15,7 +15,7 @@
<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>

Expand All @@ -35,7 +35,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.1</version>
<version>3.2.2</version>
</parent>

<properties>
Expand Down Expand Up @@ -116,8 +116,8 @@
<profile>
<id>release</id>
<properties>
<version.maven-release-plugin>3.0.0-M7</version.maven-release-plugin>
<version.maven-gpg-plugin>3.0.1</version.maven-gpg-plugin>
<version.maven-release-plugin>3.0.1</version.maven-release-plugin>
<version.maven-gpg-plugin>3.1.0</version.maven-gpg-plugin>
<version.nexus-staging-maven-plugin>1.6.13</version.nexus-staging-maven-plugin>
</properties>

Expand Down Expand Up @@ -223,7 +223,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.2.5</version>
<configuration>
<argLine>
--illegal-access=permit
Expand All @@ -237,7 +237,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<version>0.8.11</version>
<executions>
<execution>
<id>default-prepare-agent</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public HashMap<String, HashMap<String, String>> getAll() {
@Override
public String get(Locale locale, String code) {
if (this.localeExists(locale)) {
HashMap<String, String> languageCatalog = this.getLocaleHashMap(locale);
HashMap<String, String> languageCatalog = this.getLocaleMap(locale);
if (languageCatalog.containsKey(code)) {
return languageCatalog.get(code);
}
Expand All @@ -33,31 +33,31 @@ public boolean has(Locale locale, String code) {

@Override
public void put(Locale locale, String domain, String code, String targetValue) {
if (locale.toString().length() > 0) {
String concatCode = CatalogUtilities.contactCode(domain, code);
if (!locale.toString().isEmpty()) {
String concatenatedCode = CatalogUtilities.concatCode(domain, code);
if (this.localeExists(locale)) {
HashMap<String, String> transUnit = this.getLocaleHashMap(locale);
if (!transUnit.containsKey(concatCode)) {
this.getLocaleHashMap(locale).put(concatCode, targetValue);
HashMap<String, String> transUnit = this.getLocaleMap(locale);
if (!transUnit.containsKey(concatenatedCode)) {
this.getLocaleMap(locale).put(concatenatedCode, targetValue);
}
return;
}
// Init catalog for locale
HashMap<String, String> transUnit = new HashMap<>();
transUnit.put(concatCode, targetValue);
transUnit.put(concatenatedCode, targetValue);
this.catalogMap.put(CatalogUtilities.localeToKey(locale), transUnit);
}
}

public boolean localeExists(Locale locale) {
if (locale.toString().length() > 0) {
if (!locale.toString().isEmpty()) {
return this.catalogMap.containsKey(CatalogUtilities.localeToKey(locale));
}
return false;
}


private HashMap<String, String> getLocaleHashMap(Locale locale) {
private HashMap<String, String> getLocaleMap(Locale locale) {
return this.catalogMap.get(CatalogUtilities.localeToKey(locale));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.alaugks.spring.messagesource.xliff.catalog;

import io.github.alaugks.spring.messagesource.xliff.XliffCacheableKeyGenerator;
import io.github.alaugks.spring.messagesource.xliff.XliffTranslationMessageSource;
import io.github.alaugks.spring.messagesource.xliff.exception.XliffMessageSourceCacheNotExistsException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -15,7 +16,7 @@
public final class CatalogCache implements CatalogInterface {
public static final String CACHE_NAME = "messagesource.xliff.catalog.CACHE";

private static final Logger logger = LogManager.getLogger();
private static final Logger logger = LogManager.getLogger(XliffTranslationMessageSource.class.toString());
private Cache cache;

CatalogCache(CacheManager cacheManager) {
Expand Down Expand Up @@ -50,7 +51,7 @@ public boolean has(Locale locale, String code) {

@Override
public String get(Locale locale, String code) {
if (locale.toString().length() > 0) {
if (!locale.toString().isEmpty()) {
return this.getValue(
this.cache.get(
XliffCacheableKeyGenerator.createCode(locale, code)
Expand All @@ -62,11 +63,11 @@ public String get(Locale locale, String code) {

@Override
public void put(Locale locale, String domain, String code, String targetValue) {
this.put(locale, CatalogUtilities.contactCode(domain, code), targetValue);
this.put(locale, CatalogUtilities.concatCode(domain, code), targetValue);
}

void put(Locale locale, String code, String targetValue) {
if (locale.toString().length() > 0) {
if (!locale.toString().isEmpty()) {
this.cache.put(
XliffCacheableKeyGenerator.createCode(locale, code),
targetValue
Expand All @@ -83,7 +84,7 @@ private String getValue(Cache.ValueWrapper valueWrapper) {

void initCache(CatalogInterface catalog) {
if (catalog != null) {
logger.info("Init xliff catalog cache");
logger.debug("Init xliff catalog cache");
catalog.getAll().forEach((langCode, domain) -> domain.forEach((code, targetValue) ->
this.put(
Locale.forLanguageTag(langCode.replace("_", "-")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ public static String localeToKey(Locale locale) {
return buildLocale(locale).toString().trim().toLowerCase().replace("_", "-");
}

public static String contactCode(String domain, String code) {
public static String concatCode(String domain, String code) {
return domain + "." + code;
}

public static Locale buildLocale(Locale locale) {
Locale.Builder localeBuilder = new Locale.Builder();
localeBuilder.setLanguage(locale.getLanguage());
if (locale.getCountry().length() > 0) {
if (!locale.getCountry().isEmpty()) {
localeBuilder.setRegion(locale.getCountry());
}
return localeBuilder.build();
}

public static Locale buildLocale(String language, String region) {
Locale.Builder localeBuilder = new Locale.Builder();
if (language != null && language.length() > 0) {
if (language != null && !language.isEmpty()) {
localeBuilder.setLanguage(language);
// Set region only language is present
if (region != null && region.length() > 0) {
// Set region only is present
if (region != null && !region.isEmpty()) {
localeBuilder.setRegion(region);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.alaugks.spring.messagesource.xliff.catalog;

import io.github.alaugks.spring.messagesource.xliff.XliffTranslationMessageSource;
import io.github.alaugks.spring.messagesource.xliff.ressources.ResourcesLoaderInterface;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -10,7 +11,7 @@
import java.util.Objects;

public class CatalogWrapper {
private static final Logger logger = LogManager.getLogger();
private static final Logger logger = LogManager.getLogger(XliffTranslationMessageSource.class.toString());
private final CatalogCache catalogCache;
private final CatalogInterface catalog;
private final CatalogBuilderInterface catalogBuilder;
Expand Down Expand Up @@ -40,7 +41,7 @@ private static Locale buildLocaleWithLanguage(Locale locale) {

public Translation get(Locale locale, String code) {
// Check cache
String targetValue = this.getByChain(
String targetValue = this.getTranslationItemFromCatalog(
this.catalogCache,
locale,
code
Expand All @@ -53,15 +54,15 @@ public Translation get(Locale locale, String code) {

// Check catalog
CatalogInterface loadedCatalog = this.loadCatalog();
targetValue = this.getByChain(
targetValue = this.getTranslationItemFromCatalog(
loadedCatalog,
locale,
code
);

// If exists then init cache, because it was not in the cache. Cache empty?
if (targetValue != null) {
logger.info("Re-init xliff catalog cache");
logger.debug("Re-init xliff catalog cache");
this.initCache(loadedCatalog);
}

Expand Down Expand Up @@ -89,7 +90,7 @@ void put(Locale locale, String code, String targetValue) {
void put(Locale locale, String domain, String code, String targetValue) {
this.catalogCache.put(
locale,
CatalogUtilities.contactCode(domain, code),
CatalogUtilities.concatCode(domain, code),
targetValue
);
}
Expand All @@ -112,7 +113,7 @@ private CatalogInterface loadCatalog() {
return this.catalogBuilder.createCatalog(this.resourcesLoader, this.catalog);
}

private String chainLink(CatalogInterface catalog, Locale locale, String code) {
private String findTranslationItemInCatalog(CatalogInterface catalog, Locale locale, String code) {
String targetValue;
LinkedHashMap<Integer, Locale> locales = new LinkedHashMap<>();
// Follow the order
Expand Down Expand Up @@ -142,13 +143,15 @@ private String chainLink(CatalogInterface catalog, Locale locale, String code) {
return null;
}

private String getByChain(CatalogInterface catalog, Locale locale, String code) {
String targetValue = this.chainLink(catalog, locale, code);
private String getTranslationItemFromCatalog(CatalogInterface catalog, Locale locale, String code) {
// Find "code"
String targetValue = this.findTranslationItemInCatalog(catalog, locale, code);
if (targetValue == null) {
targetValue = this.chainLink(
// Find "domain.code"
targetValue = this.findTranslationItemInCatalog(
catalog,
locale,
CatalogUtilities.contactCode(this.defaultDomain, code)
CatalogUtilities.concatCode(this.defaultDomain, code)
);
}
return targetValue;
Expand Down
Loading

0 comments on commit 74799c9

Please sign in to comment.