mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 17:56:46 +00:00
feature/Make adding a new language more generic at OBP-API portal
This commit is contained in:
parent
8a0e3a9f17
commit
68f98f4a01
@ -63,20 +63,37 @@ class WebUI extends MdcLoggable{
|
||||
|
||||
def currentPage = {
|
||||
|
||||
val supportedLocales = APIUtil.getPropsValue("supported_locales","en_GB,es_ES").split(",")
|
||||
val supportedLocales: Array[String] = APIUtil.getPropsValue("supported_locales","en_GB,es_ES").split(",")
|
||||
def displayLanguage(locale: String) = {
|
||||
val hyphenLocale = locale.replace("_", "-")
|
||||
if (supportedLocales.contains(locale) || supportedLocales.contains(hyphenLocale) ) {""} else {"none"}
|
||||
// Split the string by the underscore
|
||||
val parts = hyphenLocale.split("-")
|
||||
|
||||
// Access the language and country codes
|
||||
val languageCode = parts(0)
|
||||
val countryCode = parts(1)
|
||||
languageCode.toUpperCase()
|
||||
}
|
||||
val language = I18NUtil.currentLocale().getLanguage()
|
||||
|
||||
"#es a [style]" #> s"display: ${displayLanguage("es_ES")}" &
|
||||
"#locale_separator [style]" #> {if(supportedLocales.size == 1) "display: none" else ""} &
|
||||
"#en a [style]" #> s"display: ${displayLanguage("en_GB")}" &
|
||||
"#locale_separator_ro_RO [style]" #> {if (supportedLocales.size < 3) "display: none" else ""} &
|
||||
"#ro a [style]" #> s"display: ${displayLanguage("ro_RO")}" &
|
||||
s"#${language.toLowerCase()} *" #> scala.xml.Unparsed(s"<b>${language.toUpperCase()}</b>")
|
||||
|
||||
// Dynamically generate language links
|
||||
val html = supportedLocales.toList.zipWithIndex.map { case (lang, index) =>
|
||||
// Bold selected language
|
||||
val languageAbbreviation = if (language.toLowerCase() == displayLanguage(lang).toLowerCase()) {
|
||||
s"<b>${displayLanguage(lang)}</b>"
|
||||
} else {
|
||||
s"${displayLanguage(lang)}"
|
||||
}
|
||||
// Create a span for the language link
|
||||
val link = s"""<span><a onclick="setCookie('SELECTED_LOCALE', '${lang}')" id="${displayLanguage(lang).toLowerCase()}" href="/">${languageAbbreviation}</a></span>"""
|
||||
// Add separator except for the last language
|
||||
if (index < supportedLocales.length - 1) {
|
||||
link + s"""<span id="locale_separator_${displayLanguage(lang)}">|</span>"""
|
||||
} else {
|
||||
link
|
||||
}
|
||||
}.mkString("") // Join all parts into a single string
|
||||
"#supported-language-list" #> scala.xml.Unparsed(html)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -248,13 +248,9 @@ Berlin 13359, Germany
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
<div class="language-tag" data-lift="WebUI.currentPage">
|
||||
<div class="language-tag" data-lift="WebUI.currentPage">
|
||||
<span><a href="#">Language</a></span>
|
||||
<span><a onclick="setCookie('SELECTED_LOCALE', 'en_GB')" id="en" href="/">EN</a></span>
|
||||
<span id="locale_separator">|</span>
|
||||
<span><a onclick="setCookie('SELECTED_LOCALE', 'es_ES')" id="es" href="/">ES</a></span>
|
||||
<span id="locale_separator_ro_RO">|</span>
|
||||
<span><a onclick="setCookie('SELECTED_LOCALE', 'ro_RO')" id="ro" href="/">RO</a></span>
|
||||
<div id="supported-language-list"></div>
|
||||
</div>
|
||||
<div id="copyright">
|
||||
<a href="http://openbankproject.com"><lift:loc locid="open_bank_project_is">Open Bank Project is ©2011 - </lift:loc> <span id="copyright-year" data-lift="WebUI.currentYearText">2018</span> </a> <a href="http://tesobe.com"><lift:loc locid="and_commercial_licenses">TESOBE and distributed under the AGPL and commercial licenses. </lift:loc></a>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user