在 Erlang Web 1.4 中添加国际支持
我正在尝试为基于 Erlang Web 1.4 的网站添加国际支持。
我想在每个页面上有几个链接(臭名昭著的国家标志),允许用户设置他的语言会话变量。
我现在拥有的链接如下:
<li><a href="/session/language/en">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,
{redirect, "/"}.
问题是,在设置首选语言之后,我希望用户在更改语言之前重定向到他正在访问的页面。在这种情况下,“__path”变量没有帮助,因为它包含语言请求而不是“前一个”请求。
我该如何解决这种情况? 我可能使用了错误的方法,但我现在无法做任何其他事情。
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(LanguageId) 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果请求字典确实如此有限,那么我唯一的黑客可以想到的是,您将当前页面的 url 作为 GET 变量传递回来:
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>