开发者

Adding International support in Erlang Web 1.4

开发者 https://www.devze.com 2022-12-24 19:24 出处:网络
I\'m trying to add international support for a website based on the Erlang Web 1.4. I would like to have a couple of links on every page (the notorious Country flags) that allow the user to set his l

I'm trying to add international support for a website based on the Erlang Web 1.4.

I would like to have a couple of links on every page (the notorious Country flags) that allow the user to set his language session variable.

What I have right now is a link like:

<li><a href="/session/language/en">English</a></li>

Where, in the session controller I do:

language(Args) ->
    LanguageId = proplists:get_value(id, Args),
    case language_is_supported(Language开发者_开发知识库Id) of
        false ->
            ok;
        true ->
            wpart:fset("session:lang", LanguageId)
    end,
    {redirect, "/"}.

The problem is that, after setting the preferred language, I would like the user to be redirected to the page he was visiting before changing the language. In this case the "__path" variable doesn't help because it contains the language request and not the "previous" one.

How could I resolve this situation? I'm probably using the wrong approach but I cannot thing to anything else right now.


If the request dictionary is really so limited, the only hack I can think of is that you pass the current page's url back as a GET variable:

<li><a href="/session/language/en?referrer=/path/to/current/page">English</a></li>

language(Args) ->
    LanguageId = proplists:get_value(id, Args),
    case language_is_supported(LanguageId) of
        false -> ok;
        true ->  wpart:fset("session:lang", LanguageId)
    end,
    Referrer = eptic:fget("get", "referrer"),
    {redirect, Referrer}.
0

精彩评论

暂无评论...
验证码 换一张
取 消