Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback-functionality #25

Closed
thomkle opened this issue Mar 9, 2020 · 12 comments · Fixed by #26
Closed

Fallback-functionality #25

thomkle opened this issue Mar 9, 2020 · 12 comments · Fixed by #26

Comments

@thomkle
Copy link

thomkle commented Mar 9, 2020

Any plans to support fallback-functionality? E.g. say I have a TestController and the files testcontroller.es-ES.json, testcontroller.es.json and testcontroller.json. The fallback-functionality would first check the testcontroller.es-ES.json for the key, then the testcontroller.es.json and then testcontroller.json.

Edit: Like explained here

@hishamco
Copy link
Owner

hishamco commented Mar 9, 2020

Any plans to support fallback-functionality?

Sure, let me check why this not included, I already support this in some OSS

@hishamco
Copy link
Owner

hishamco commented Mar 9, 2020

FYI the fallback is here https://github.com/hishamco/My.Extensions.Localization.Json/blob/master/src/My.Extensions.Localization.Json/JsonStringLocalizer.cs#L119-L140

Are you sure it doesn't work, perhaps I need to add a unit test if it is not included yet

@thomkle
Copy link
Author

thomkle commented Mar 9, 2020

That's really strange, to provide more accurate info:
I have a test.en-US.json, test.en.json and test.json (in the same folder) with the following content:

test.en-US.json

{
  "temp":  "test-en-US"
}

test.en.json

{
  "temp": "test-en",
  "temp2": "test-en"
}

test.json

{
  "temp": "test",
  "temp2": "test",
  "temp3": "test"
}

With an empty Test-class:

public class Test
{
}

And then trying to access the values using IStringLocalizer<Test> _localizer (injected into a controller) and _localizer["temp"] == "test-en-US" (which is correct), but _localizer["temp2"] == "temp2" and _localizer["temp3"] == "temp3".

Do you have an example where the fallback-functionality is used? Maybe I'm missing something.

@hishamco
Copy link
Owner

hishamco commented Mar 9, 2020

I know what you mean exactly, let me create a unit test for that

@thomkle
Copy link
Author

thomkle commented Mar 10, 2020

Great, thanks for being so fast to respond!

@hishamco
Copy link
Owner

@thomkle seems the culture fallback works fine with GetAllStrings() but not localizer indexer

@thomkle
Copy link
Author

thomkle commented Mar 11, 2020

@hishamco Ah, I see. I'll follow the status on #26

@hishamco
Copy link
Owner

It's already merged ;) feel free to use and try the latest bits

@thomkle
Copy link
Author

thomkle commented Mar 11, 2020

Ah, great! I'll try out the last change. Could you push a NuGet package for it as well?

@thomkle
Copy link
Author

thomkle commented Mar 11, 2020

@hishamco Seems to be working very well now, thanks!

@thomkle
Copy link
Author

thomkle commented Mar 11, 2020

@hishamco Sorry to nag, but the fallback doesn't seem to work completely. E.g. say I have set the culture "es-ES", but there are no files .es-ES.json, but I have a .json. It will not fall back to values in .json. I also tested this creating unit tests after cloning the repo and it looks that the unit test fails.
Reproduction steps:

  • Add a Test.json with the content { "Hello": "Hello there" }
  • In the JsonStringLocalizerTests for the method GetTranslation add the inline data: [InlineData("es-ES", "Hello", "Hello there")]. This will fail, but this kind of fallback should work, right?

I'll be happy to try to solve this my self and create pull requests, but I understand if you're more comfortable with solving things in the project yourself :)

@hishamco
Copy link
Owner

Could you push a NuGet package for it as well?

I'm not sure for now, but may be a pre release version will be fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants