forked from ontoportal/ontoportal_web_ui
-
Notifications
You must be signed in to change notification settings - Fork 6
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 #228 from ontoportal-lirmm/feature/support-multi-l…
…ingual Feature | Support multi-lingual: UI Internationalization
- Loading branch information
1 parent
8e8ce1a
commit 71c852a
Showing
34 changed files
with
1,439 additions
and
564 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class LanguageController < ApplicationController | ||
|
||
# set locale to the language selected by the user | ||
def set_locale_language | ||
language = params[:language].strip.downcase.to_sym | ||
supported_languages = I18n.available_locales | ||
|
||
if language | ||
if supported_languages.include?(language) | ||
cookies.permanent[:locale] = language | ||
else | ||
# in case we want to show a message if the language is not available | ||
flash.now[:notice] = "#{language} translation not available" | ||
logger.error flash.now[:notice] | ||
end | ||
end | ||
|
||
redirect_to request.referer || root_path | ||
end | ||
|
||
end |
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
21 changes: 21 additions & 0 deletions
21
app/javascript/controllers/platform_language_controller.js
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,21 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
import { Turbo } from "@hotwired/turbo-rails"; | ||
import { getCookie } from "../mixins/cookie"; | ||
|
||
// Connects to data-controller="platform-language" | ||
// this controller is used to change the language of the whole platform | ||
export default class extends Controller { | ||
|
||
connect() { | ||
const locale = getCookie('locale'); | ||
|
||
const option = document.querySelector(`#language-select option[value="${locale}"]`); | ||
option && (option.selected = true); | ||
|
||
} | ||
|
||
handleLangChanged(event) { | ||
const userPreferedLanguage = event.target.value; | ||
Turbo.visit(`/locale/${userPreferedLanguage}`, { action: "replace" }); | ||
} | ||
} |
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,8 @@ | ||
export const getCookie = (name) => { | ||
const cookieValue = document.cookie.match('(^|[^;]+)\\s*' + name + '\\s*=\\s*([^;]+)'); | ||
return cookieValue ? cookieValue.pop() : ''; | ||
} | ||
|
||
export const setCookie = (name, value, days) => { | ||
document.cookie = `${name}=${value};max-age=${days * 24 * 60 * 60}`; | ||
} |
Oops, something went wrong.