-
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.
Merge pull request #48 from Thibstars/feature/47/Use-correct-language…
…-in-iRail-API-calls
- Loading branch information
Showing
15 changed files
with
165 additions
and
41 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
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
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
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); | ||
} | ||
} |
Oops, something went wrong.