Allow Json Language resources to be loaded from EmbeddedResource files #55

Closed
slodge opened this Issue Nov 19, 2012 · 11 comments

Comments

Projects
None yet
5 participants
@slodge
Contributor

slodge commented Nov 19, 2012

Following up from this StackOverflow post (http://stackoverflow.com/questions/13455635/mvvmcross-localization-switch-at-runtime) one thing that occurred to me is that we don't really need to load Mvx Json text files from UI projects any more.

Instead I think we could quite happily use EmbeddedResource files within the Core/ViewModel project.

To make this work, we'd need to change GetTextResource so that it can use the EmbeddedResource code instead of Resource (Asset/Content based code).

Should be easy enough to do.... obviously would want to make it switchable so that old code carries on working...

@Alphapage

This comment has been minimized.

Show comment Hide comment
@Alphapage

Alphapage Nov 21, 2012

Contributor

My updated gist do the job:
https://gist.github.com/4119823
Just add PCL project including json files as EmbeddedResource and run binder.LoadEmbeddedResource("customLanguage") instead of binder.LoadResource from ConferenceApp for example, you are done.
Tested on Droid only but will work on windows and don't have time to test with monotouch.

The most exciting feature is that you can store all your strings inside the PCL to share with other platforms even if you don't provide another language: you update the json file and all platforms are updated.

Contributor

Alphapage commented Nov 21, 2012

My updated gist do the job:
https://gist.github.com/4119823
Just add PCL project including json files as EmbeddedResource and run binder.LoadEmbeddedResource("customLanguage") instead of binder.LoadResource from ConferenceApp for example, you are done.
Tested on Droid only but will work on windows and don't have time to test with monotouch.

The most exciting feature is that you can store all your strings inside the PCL to share with other platforms even if you don't provide another language: you update the json file and all platforms are updated.

@slodge

This comment has been minimized.

Show comment Hide comment
@slodge

slodge Nov 21, 2012

Contributor

thanks - agree 100% on 'The most exciting feature' :)

Will try to get this in soon.

On a side note - apologies if the current build tree changes affect you in any way - just trying to get the build more robust and trying to get back to a level where we can distribute executables again :)

Contributor

slodge commented Nov 21, 2012

thanks - agree 100% on 'The most exciting feature' :)

Will try to get this in soon.

On a side note - apologies if the current build tree changes affect you in any way - just trying to get the build more robust and trying to get back to a level where we can distribute executables again :)

@Alphapage

This comment has been minimized.

Show comment Hide comment
@Alphapage

Alphapage Nov 22, 2012

Contributor

I forgot to tell the MvxTextProviderBuilder initializes with LoadEmbeddedResources(string.Empty,false); by default.
If you want to use assets you will have to force LoadResources like this:
var builder = new TextProviderBuilder();
// TODO - could choose a language here: builder.LoadResources(whichLanguage);
builder.LoadResources("");
this.RegisterServiceInstance(builder.TextProvider);

Contributor

Alphapage commented Nov 22, 2012

I forgot to tell the MvxTextProviderBuilder initializes with LoadEmbeddedResources(string.Empty,false); by default.
If you want to use assets you will have to force LoadResources like this:
var builder = new TextProviderBuilder();
// TODO - could choose a language here: builder.LoadResources(whichLanguage);
builder.LoadResources("");
this.RegisterServiceInstance(builder.TextProvider);

@Alphapage

This comment has been minimized.

Show comment Hide comment
@Alphapage

Alphapage Nov 22, 2012

Contributor

I added support to this kind of json formatting:
{
"Text":["string1","string2","string3"],
"":["string1 en","string2 en","string3 en"],
"fr":["string1 in French","string2 in fr","string3 fr"],
"fr-be":["string1 in fr-be","string2 in fr-be","string3 fr-be"],
}

With little effort, one can export to excel, add a new column language, modify values,translate from English quickly and save to json. I will use this formatting which is set by default in my updated gist.

Contributor

Alphapage commented Nov 22, 2012

I added support to this kind of json formatting:
{
"Text":["string1","string2","string3"],
"":["string1 en","string2 en","string3 en"],
"fr":["string1 in French","string2 in fr","string3 fr"],
"fr-be":["string1 in fr-be","string2 in fr-be","string3 fr-be"],
}

With little effort, one can export to excel, add a new column language, modify values,translate from English quickly and save to json. I will use this formatting which is set by default in my updated gist.

@slodge

This comment has been minimized.

Show comment Hide comment
@slodge

slodge Nov 22, 2012

Contributor

Thanks

I like the idea of excel editable.

What we probably need to do is to split out implementations from interface so that users can use ITextProvider and just pick which version they want to use - some people will prefer separate files.... I'll probably go for a single spreadsheet.

Thanks again. Will work on this 'soon' - meaning before Xmas (I hope)

Contributor

slodge commented Nov 22, 2012

Thanks

I like the idea of excel editable.

What we probably need to do is to split out implementations from interface so that users can use ITextProvider and just pick which version they want to use - some people will prefer separate files.... I'll probably go for a single spreadsheet.

Thanks again. Will work on this 'soon' - meaning before Xmas (I hope)

@slodge

This comment has been minimized.

Show comment Hide comment
@slodge

slodge Dec 7, 2012

Contributor

I have gotten a little way with this.... bit only a little

Still hope to do this before Xmas!

Contributor

slodge commented Dec 7, 2012

I have gotten a little way with this.... bit only a little

Still hope to do this before Xmas!

slodge added a commit that referenced this issue Dec 7, 2012

@slodge

This comment has been minimized.

Show comment Hide comment
@slodge

slodge Dec 21, 2012

Contributor

@Alphapage I've not forgotten about this... but I have run out of time - will add this as soon as I can... Sorry for the delay and Thanks for the enthusiasm!

Contributor

slodge commented Dec 21, 2012

@Alphapage I've not forgotten about this... but I have run out of time - will add this as soon as I can... Sorry for the delay and Thanks for the enthusiasm!

@slodge

This comment has been minimized.

Show comment Hide comment
@slodge

slodge Feb 22, 2013

Contributor

Just linking in #53 and #63 and marking this as v3.

Contributor

slodge commented Feb 22, 2013

Just linking in #53 and #63 and marking this as v3.

@slodge

This comment has been minimized.

Show comment Hide comment
@slodge

slodge Mar 10, 2013

Contributor

Half of this done tonight....

But more still needed....

Especially to support:

{
"Text":["string1","string2","string3"],
"":["string1 en","string2 en","string3 en"],
"fr":["string1 in French","string2 in fr","string3 fr"],
"fr-be":["string1 in fr-be","string2 in fr-be","string3 fr-be"],
}
Contributor

slodge commented Mar 10, 2013

Half of this done tonight....

But more still needed....

Especially to support:

{
"Text":["string1","string2","string3"],
"":["string1 en","string2 en","string3 en"],
"fr":["string1 in French","string2 in fr","string3 fr"],
"fr-be":["string1 in fr-be","string2 in fr-be","string3 fr-be"],
}
@dot-ly

This comment has been minimized.

Show comment Hide comment
@dot-ly

dot-ly May 17, 2016

Can i now use JSON files in the PCL for localisation? any examples? cheers

dot-ly commented May 17, 2016

Can i now use JSON files in the PCL for localisation? any examples? cheers

martijn00 added a commit to martijn00/MvvmCross that referenced this issue Dec 8, 2016

Merge pull request #55 from ggirard07/windowsUWPFilePluginFixCreateFo…
…lderAsync

Fixed folder path ended by a separator not properly handled on WindowsUWP

martijn00 added a commit to martijn00/MvvmCross that referenced this issue Dec 8, 2016

Merge pull request #55 from zzcgumn/pagerendererexample
Examples for MvxContentPage and MvxPageRenderer

martijn00 added a commit to martijn00/MvvmCross that referenced this issue Dec 8, 2016

Merge pull request #55 from b099l3/master
Fix for MvxExpandableTableViewSource: GetViewForHeader adding multiple buttons

kjeremy pushed a commit to kjeremy/MvvmCross that referenced this issue Dec 11, 2016

@martijn00

This comment has been minimized.

Show comment Hide comment
@martijn00

martijn00 Jan 10, 2018

Owner

This is already possible.

Owner

martijn00 commented Jan 10, 2018

This is already possible.

@martijn00 martijn00 closed this Jan 10, 2018

@nmilcoff nmilcoff added the Deprecated label Jan 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment