-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
83 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/github/thibstars/btsd/irail/helper/LanguageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.github.thibstars.btsd.irail.helper; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* @author Thibault Helsmoortel | ||
*/ | ||
public interface LanguageService { | ||
|
||
Set<String> getSupportedLanguages(); | ||
|
||
String getLanguageOrFallback(String language); | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/github/thibstars/btsd/irail/helper/LanguageServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.github.thibstars.btsd.irail.helper; | ||
|
||
import java.util.Optional; | ||
import java.util.Set; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* @author Thibault Helsmoortel | ||
*/ | ||
public class LanguageServiceImpl implements LanguageService { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(LanguageServiceImpl.class); | ||
|
||
private static final Set<String> SUPPORTED_LANGS = Set.of("en", "nl", "fr", "de"); | ||
|
||
|
||
@Override | ||
public Set<String> getSupportedLanguages() { | ||
return SUPPORTED_LANGS; | ||
} | ||
|
||
@Override | ||
public String getLanguageOrFallback(String language) { | ||
Optional<String> optionalLanguage = SUPPORTED_LANGS.stream() | ||
.filter(lang -> lang.equals(language)) | ||
.findFirst(); | ||
|
||
String fallbackLanguage = SUPPORTED_LANGS.stream().findFirst().orElseThrow(); | ||
if (optionalLanguage.isEmpty()) { | ||
LOGGER.warn("Language {} is not supported, using {} as a fallback.", language, fallbackLanguage); | ||
} | ||
|
||
return optionalLanguage.orElse(fallbackLanguage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters