czyzby / gdx-lml

:octocat: LibGDX utility libraries.
Apache License 2.0
159 stars 25 forks source link

Parameterizing localization strings with arguments #36

Open metaphore opened 8 years ago

metaphore commented 8 years ago

Following this example from wiki @key|only|@arg I'm trying to pass argument to localized string as parameter:

<vislabel>@key|{arg}</vislabel>

But as result parser searches for key|{arg} key in bundle (and crushes when not found).

Am I missing something?

czyzby commented 8 years ago

Could you provide a code sample or a small project that recreates the issue? Or paste the complete stack trace of the exception? When I used this snippet in gdx-lml-tests, it worked fine:

<:argument key="sample" value="test"/>
<label>@bundleLineWithArgument|{sample}</label>

This prints Received argument: test. as expected.

czyzby commented 8 years ago

@metaphore Is this still an issue?

metaphore commented 8 years ago

@czyzby sorry, had no time to prepare code sample and check it once again. Will do it till the end of this week

czyzby commented 8 years ago

Not a problem, take your time.

metaphore commented 8 years ago

I had few experiments but for good (or bad) can't reproduce it anymore. I think it should be closed now and if problem will ever occur, I will supply you with details in that issue.

BTW, is there a way to conjunct two expressions next to each other like: @someString{someValue}?

czyzby commented 8 years ago

BTW, is there a way to conjunct two expressions next to each other like: @someString{someValue}?

I think that in this particular example it would currently replace someValue and look for I18N line named someStringSomeValueResult.

But labels are not multiline by default (you have to enable it first), so something like this:

<label>@someString
{someValue}</label>

...would result in a single string, joining the two inputs.

metaphore commented 7 years ago

@czyzby probably I found what is origin problem was about. If I try to parametrize localized string with a value started with . (e.g. file extension) it results in

I18N bundle not found for bundle line: @key.arg

And I guess it's pretty obvious why - LML treats key as a bundle name. But still it looks like there is no way to put any value that starts from dot. May be is it possible to add some kind of escape character for such case?

czyzby commented 7 years ago

Can you post a self-contained example of a LML template and the bundle line argument that reproduce the issue, so I can test it easily? I'll look into it before the next release.

Anyway, I suggest going for a workaround for now, like using a Java method for building this particular string or avoiding parametrization (if possible) when an argument with dot is present.

metaphore commented 7 years ago

Sure, thanks. I believe this should be enough to reproduce the case:

bundle.properties

key = text {0} text

template.lml

<?xml version="1.0"?>
<!DOCTYPE label SYSTEM>

<label text="@key|.value"/>