Skip to content

Commit

Permalink
Merge pull request #487 from eyra/pass-locale-to-feldspar-app
Browse files Browse the repository at this point in the history
Pass locale to feldspar app
  • Loading branch information
mellelieuwes authored Nov 24, 2023
2 parents b187cbf + 1614a28 commit 35e534b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
8 changes: 7 additions & 1 deletion core/assets/js/feldspar_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export const FeldsparApp = {
mounted() {
console.log("FeldsparApp MOUNTED");

console.log(this.el.dataset);

const iframe = this.getIframe();
iframe.addEventListener("load", () => {
this.onFrameLoaded();
Expand All @@ -19,7 +21,11 @@ export const FeldsparApp = {
this.channel.port1.onmessage = (e) => {
this.handleMessage(e);
};
this.getIframe().contentWindow.postMessage("init", "*", [

let action = "live-init";
let locale = this.el.dataset.locale;

this.getIframe().contentWindow.postMessage({ action, locale }, "*", [
this.channel.port2,
]);
},
Expand Down
1 change: 0 additions & 1 deletion core/lib/core_web/live_locale.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ defmodule CoreWeb.LiveLocale do
def mount(params, %{"locale" => locale} = session, socket) do
Gettext.put_locale(CoreWeb.Gettext, locale)
Gettext.put_locale(Timex.Gettext, locale)
Gettext.get_locale()
super(params, session, socket)
end
end
Expand Down
2 changes: 1 addition & 1 deletion core/systems/feldspar/app_page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule Systems.Feldspar.AppPage do
def render(assigns) do
~H"""
<.stripped menus={@menus} footer?={false}>
<.app_view url={@app_url} />
<.app_view url={@app_url} locale={Gettext.get_locale()} />
</.stripped>
"""
end
Expand Down
3 changes: 2 additions & 1 deletion core/systems/feldspar/app_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule Systems.Feldspar.AppView do
use CoreWeb, :html

attr(:url, :string, required: true)
attr(:locale, :string, required: true)

def app_view(assigns) do
~H"""
Expand All @@ -10,7 +11,7 @@ defmodule Systems.Feldspar.AppView do
Changing the preceding siblings of the iframe would result in a reload of the iframe
due to Morphdom (https://github.com/patrick-steele-idem/morphdom/issues/200).
--%>
<div class="w-full h-full" phx-update="ignore" id="web-app-frame" phx-hook="FeldsparApp" data-src={@url}>
<div class="w-full h-full" phx-update="ignore" id="web-app-frame" phx-hook="FeldsparApp" data-locale={@locale} data-src={@url}>
<iframe class="w-full h-full"></iframe>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion core/systems/feldspar/tool_model.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ defmodule Systems.Feldspar.ToolModel do
def launcher(%{archive_ref: archive_ref}) when is_binary(archive_ref) do
%{
function: &Feldspar.AppView.app_view/1,
props: %{url: archive_ref <> "/index.html"}
props: %{
url: archive_ref <> "/index.html",
locale: Gettext.get_locale(CoreWeb.Gettext)
}
}
end

Expand Down

0 comments on commit 35e534b

Please sign in to comment.