RejectedSoftware Forums

Sign up

Pages: 1 2

i18n

As far as I can tell, localization via .po files is chosen based on HTTP
headers.
Is it also possible to manually choose the language?
I would like to let the user choose their language, instead of forcing
ie. German on everyone in Germany, even through they're a foreigner, or
have different preferences.

Thanks :)

ps. I get this error when using the website frontend:
500 - Internal Server Error

Internal Server Error

Internal error information:
object.Exception@source/vibenews/controller.d(381): Unknown article id!

./vibenews(pure @safe bool std.exception.enforce!(bool).enforce(bool,
lazy const(char)[], immutable(char)[], ulong)+0x6b) [0x7d6fef]
./vibenews(vibenews.controller.GroupRef[immutable(char)[]]
vibenews.controller.Controller.getArticleGroupRefs(vibe.data.bson.BsonObjectID)+0x178)
[0x8c2d7c]
./vibenews(void
vibenews.web.WebInterface.redirectToThreadPost(vibe.http.server.HTTPServerResponse,
immutable(char)[], immutable(char)[], long, vibe.data.bson.BsonObjectID,
vibe.http.status.HTTPStatus)+0x1ec) [0x8e7398]
./vibenews(void
vibenews.web.WebInterface.postArticle(vibe.http.server.HTTPServerRequest, vibe.http.server.HTTPServerResponse)+0xd84)
[0x8e7178]
./vibenews(void
vibe.http.router.URLRouter.handleRequest(vibe.http.server.HTTPServerRequest,
vibe.http.server.HTTPServerResponse).void lambda3!(ulong,
immutable(char)[][]).
lambda3(ulong, scope immutable(char))+0x1dc)
[0x94e888]
./vibenews(void
vibe.http.router.MatchTree!(vibe.http.router.Route).MatchTree.match(immutable(char)[],
scope void delegate(ulong, scope immutable(char)))+0x1dc) [0x94eec8]
./vibenews(void
vibe.http.router.URLRouter.handleRequest(vibe.http.server.HTTPServerRequest,
vibe.http.server.HTTPServerResponse)+0x1a6) [0x94e63a]
./vibenews(bool vibe.http.server.handleRequest(vibe.core.stream.Stream,
vibe.core.net.TCPConnection, vibe.http.server.HTTPServerListener, ref
vibe.http.server.HTTPServerSettings, ref bool)+0x1654) [0x9bb310]
./vibenews(void
vibe.http.server.handleHTTPConnection(vibe.core.net.TCPConnection,
vibe.http.server.HTTPServerListener)+0x17e) [0x9b9bda]
./vibenews(void
vibe.http.server.listenHTTPPlain(vibe.http.server.HTTPServerSettings).doListen(vibe.http.server.HTTPServerSettings,
vibe.http.server.HTTPServerListener,
immutable(char)[]).lambda4(vibe.core.net.TCPConnection)+0x2c) [0x9b98ec]
./vibenews(void vibe.core.drivers.libevent2_tcp.onConnect(int, short,
void*).ClientTask.execute()+0x316) [0x926e3a]
./vibenews(_D4vibe4core4core27
T16makeTaskFuncInfoTDFZvZ16makeTaskFuncInfoFNbDFZvZS4vibe4core4core12TaskFuncInfo12callDelegateFPS4vibe4core4core12TaskFuncInfoZv+0xda)
[0x866abe]
./vibenews(void vibe.core.core.CoreTask.run()+0x173) [0x90e733]
./vibenews(void core.thread.Fiber.run()+0x2a) [0xa4e432]
./vibenews(fiber_entryPoint+0x61) [0xa4e33d]
[(nil)]

Re: i18n

On Mon, 01 Sep 2014 22:35:52 +0200, Lemonfiend wrote:

As far as I can tell, localization via .po files is chosen based on HTTP
headers.
Is it also possible to manually choose the language?
I would like to let the user choose their language, instead of forcing
ie. German on everyone in Germany, even through they're a foreigner, or
have different preferences.

Thanks :)

Currently there is no hook to override that, but I'll add that for the next version. But the languages can also be configured in the user's browser and are not dependent on the location. They are usually chosen at installation time based on the system locale settings.

ps. I get this error when using the website frontend:
500 - Internal Server Error

For some reason your messages have been recognized as spam and the error message for that is still not correct (there is already an open ticket for this). I've manually classified them as non-spam now (but left them disabled in favor of this one).

Re: i18n

On Tue, 02 Sep 2014 10:20:20 GMT, Sönke Ludwig wrote:

On Mon, 01 Sep 2014 22:35:52 +0200, Lemonfiend wrote:

As far as I can tell, localization via .po files is chosen based on HTTP
headers.
Is it also possible to manually choose the language?
I would like to let the user choose their language, instead of forcing
ie. German on everyone in Germany, even through they're a foreigner, or
have different preferences.

Thanks :)

Currently there is no hook to override that, but I'll add that for the next version. But the languages can also be configured in the user's browser and are not dependent on the location. They are usually chosen at installation time based on the system locale settings.

Done: da90308

Re: i18n

For some reason your messages have been recognized as spam and the

error message for that is still not correct (there is already an open
ticket for this). I've manually classified them as non-spam now (but
left them disabled in favor of this one).
Ah, I see.

Done:

da90308

Great, thanks!

Re: i18n

On Tue 02 Sep 13:46, Sönke Ludwig wrote:

On Tue, 02 Sep 2014 10:20:20 GMT, Sönke Ludwig wrote:

On Mon, 01 Sep 2014 22:35:52 +0200, Lemonfiend wrote:

As far as I can tell, localization via .po files is chosen based on HTTP
headers.
Is it also possible to manually choose the language?
I would like to let the user choose their language, instead of forcing
ie. German on everyone in Germany, even through they're a foreigner, or
have different preferences.

Thanks :)

Currently there is no hook to override that, but I'll add that for the next version. But the languages can also be configured in the user's browser and are not dependent on the location. They are usually chosen at installation time based on the system locale settings.

Done: da90308

I finally got a chance to look into this a bit further.

Am I correct in that you have to choose between EITHER the
Accept-Language header, OR determineLanguage, but not both?

As in, when returning null from determineLanguage it defaults to the
TranslationContext's languages default (the first?), and disregards the
header completely? This means you HAVE to have a default language which
is the same for everyone, which is bad.

I'd like it to first check determineLanguage. If it return non-null, use
that. If it's null, use the regular headers method.
This would make the following common scenario possible.
User visits page: language == header
User chooses language/logs in: language == determineLanguage (via a
sessionvar).

Thanks!

Re: i18n

On Wed 24 Sep 03:17, Lemonfiend wrote:

On Tue 02 Sep 13:46, Sönke Ludwig wrote:

On Tue, 02 Sep 2014 10:20:20 GMT, Sönke Ludwig wrote:

On Mon, 01 Sep 2014 22:35:52 +0200, Lemonfiend wrote:

As far as I can tell, localization via .po files is chosen based on
HTTP
headers.
Is it also possible to manually choose the language?
I would like to let the user choose their language, instead of forcing
ie. German on everyone in Germany, even through they're a foreigner, or
have different preferences.

Thanks :)

Currently there is no hook to override that, but I'll add that for
the next version. But the languages can also be configured in the
user's browser and are not dependent on the location. They are
usually chosen at installation time based on the system locale settings.

Done:
da90308

I finally got a chance to look into this a bit further.

Am I correct in that you have to choose between EITHER the
Accept-Language header, OR determineLanguage, but not both?

As in, when returning null from determineLanguage it defaults to the
TranslationContext's languages default (the first?), and disregards the
header completely? This means you HAVE to have a default language which
is the same for everyone, which is bad.

I'd like it to first check determineLanguage. If it return non-null, use
that. If it's null, use the regular headers method.
This would make the following common scenario possible.
User visits page: language == header
User chooses language/logs in: language == determineLanguage (via a
sessionvar).

Thanks!

While the example works fine, I had some trouble getting it to work in
my own project. I finally realized the difference: render vs renderCompat.
It works in render, but not in renderCompat!

Re: i18n

Am 24.09.2014 04:31, schrieb Lemonfiend:

On Wed 24 Sep 03:17, Lemonfiend wrote:

On Tue 02 Sep 13:46, Sönke Ludwig wrote:

On Tue, 02 Sep 2014 10:20:20 GMT, Sönke Ludwig wrote:

On Mon, 01 Sep 2014 22:35:52 +0200, Lemonfiend wrote:

As far as I can tell, localization via .po files is chosen based on
HTTP
headers.
Is it also possible to manually choose the language?
I would like to let the user choose their language, instead of forcing
ie. German on everyone in Germany, even through they're a
foreigner, or
have different preferences.

Thanks :)

Currently there is no hook to override that, but I'll add that for
the next version. But the languages can also be configured in the
user's browser and are not dependent on the location. They are
usually chosen at installation time based on the system locale
settings.

Done:
da90308

I finally got a chance to look into this a bit further.

Am I correct in that you have to choose between EITHER the
Accept-Language header, OR determineLanguage, but not both?

As in, when returning null from determineLanguage it defaults to the
TranslationContext's languages default (the first?), and disregards the
header completely? This means you HAVE to have a default language which
is the same for everyone, which is bad.

I'd like it to first check determineLanguage. If it return non-null, use
that. If it's null, use the regular headers method.
This would make the following common scenario possible.
User visits page: language == header
User chooses language/logs in: language == determineLanguage (via a
sessionvar).

Thanks!

While the example works fine, I had some trouble getting it to work in
my own project. I finally realized the difference: render vs renderCompat.
It works in render, but not in renderCompat!

Yes, and it also works only with vibe.web.web.render! So using
res.render!() in particular won't work, as well as
res.renderCompat!(). Those are just the plain template rendering
functions without any translation support.

I'll change the logic of determineLanguage to fall back to the default
algorithm instead of the default language.

Re: i18n

Yes, and it also works only with vibe.web.web.render! So using
res.render!() in particular won't work, as well as
res.renderCompat!(). Those are just the plain template rendering
functions without any translation support.

Ah I see.

I'll change the logic of determineLanguage to fall back to the default
algorithm instead of the default language.

Thanks!

Btw. Is it possible to translate things like this?
input&(type="text", placeholder=myi18nplaceholder)

Re: i18n

On Thu 25 Sep 08:13, Lemonfiend wrote:

Yes, and it also works only with vibe.web.web.render! So using
res.render!() in particular won't work, as well as
res.renderCompat!(). Those are just the plain template rendering
functions without any translation support.
Ah I see.

I'll change the logic of determineLanguage to fall back to the default
algorithm instead of the default language.
Thanks!

Btw. Is it possible to translate things like this?
input&(type="text", placeholder=myi18nplaceholder)

Oh, and is it possible to mark a method as NOT being a route?

It seems render can only be called from a method that is public, and
public methods are parsed added as a @path automatically. But the method
where I call render is a helper function, something like:

class Webber
{

@path(`/`)
void get()
{
	if(something)
		_getA();
	else
		_getB();
}

protected void _getA()
{
	// do stuff

	render!(indexA.dt);
}

// etc.

}

Re: i18n

Am 25.09.2014 08:30, schrieb Lemonfiend:

On Thu 25 Sep 08:13, Lemonfiend wrote:

Yes, and it also works only with vibe.web.web.render! So using
res.render!() in particular won't work, as well as
res.renderCompat!(). Those are just the plain template rendering
functions without any translation support.
Ah I see.

I'll change the logic of determineLanguage to fall back to the default
algorithm instead of the default language.
Thanks!

Btw. Is it possible to translate things like this?
input&(type="text", placeholder=myi18nplaceholder)

Currently only by using the undocumented diet_translate__ function:

input(type="text", placeholder=diet_translate__("my_i18n_placeholder"))

I didn't put enough thought into a final solution, but maybe I will just
end up renaming diet_translate__ to simply tr and make it publicly
documented.

Alternatively, a syntax using & would be an option:

input(type="text", placeholder&="my_i18n_placeholder")

Oh, and is it possible to mark a method as NOT being a route?

It should be the case that only public functions are registered, so
either private, package or protected should cause it to be ignored.

On top of that, there should definitely also be an annotation, such as
@ignore, in the future. I'm just not sure so far if it is a good idea
to reuse vibe.data.serialization.ignore or if it's better to define a
new vibe.web.common.noRoute attribute. Probably the latter...

Pages: 1 2