Embedding language specific generated assemblies

Apr 21, 2013 at 9:26 PM
Hello,

First of all, thank you very much for this useful tool. I use it everytime I need to localize my WPF apps.
I'm developing a small WPF application and would like to output only 1 exe file.
Using the following link : http://www.digitallycreated.net/Blog/61/combining-multiple-assemblies-into-a-single-exe-for-a-wpf-application, I succeeded in embedding all the dlls of my solution (including WPFLocalizeExtension.dll) except for the localization dlls (xx-XX/xxx.resources.dll).

Do you know if there is any way to achieve this ?

Regards,

Kormyr
Coordinator
Apr 24, 2013 at 10:55 AM
Hi Kormyr,

as far as I know it is not possible. Maybe you can do some magic with AL.exe but I wouldn't count on that.

Cheers
Apr 24, 2013 at 12:02 PM
Hi,

Thanks for your reply, I'll give it a try.
After a quick look in the source code, it seems to look for "culture folders" ("fr-FR", "en-US" or "FR", "EN", ...).
Do you think I will have to change the WPF Localize Extension source code ?
Like, for example, change the behavior to look for files named AppName.fr-FR.resources.dll and AppName.en-US.resources.dll instead of fr-FR\AppName.resources.dll and en-US.resources.dll.

Regards,

Kormyr
Coordinator
Apr 24, 2013 at 2:10 PM
Hi,

we do not search for resources our own, at least not with the default resource provider. We rely on microsofts resource manager and already loaded assemblies.

you either can try to load the resources before you switch the language or write your own provider. Here is an example for a CSV provider.

Cheers!
Apr 26, 2013 at 8:55 PM
Hi,

Good news, I finally found a way to get it working.
I used the CSV example, adapted it for embedded files and added some functionality from the classic Resx provider.

I don't think it's not perfect enough to be added to the examples but if you want I can provide the modifications.
The issues I still have are :
  • At runtime the behaviour is ok but at design time there are errors on xaml files in VS2012
  • Some characters are not rendering correctly "é","è",... (encoding issue ?)
  • Images are not supported (^^)
Kormyr
Coordinator
Apr 29, 2013 at 7:18 AM
Hi,

We are happy about fresh ideas and contributions so please feel free to send us your copy or better make a pull request on github.

Best regards,
Uwe
Apr 30, 2013 at 12:59 PM
Edited Apr 30, 2013 at 1:04 PM
Hi,

I've done the pull request.

Regarding my previous post:
I managed to fix the issues I add, except for Images (of course ^^, or you can localize the file names in your application).
I do not have VS error messages but there are still some strange issues at design time (sometimes translation is showing correctly, and switching instantly when changing design culture, sometimes it is not showing anything).

Regarding the changes:
I added 3 files:
  • CSVLocalizationProviderBase: Equivalent of the ResxLocalizationProviderBase (there should be a lot of code that could be removed)
  • CSVLocalizationProvider: Use it if you need a localization with CSV files. File name: <dictionary>.<culture>.csv (currently, the root directory for CSV files is hardcoded: the "Localization" folder, this could be changed to a property if needed)
  • CSVEmbeddedLocalizationProvider: Use it if you need a localization with embedded CSV files. File name: <dictionary>-<culture>.csv (I was not able to get it working with the classic notation, so I used a dash instead of a dot)
To switch between providers, you still have to replace the provider name occurrences in files:
  • XAML files: Example: "Providers:<yourprovider>.DefaultAssembly=" or "Providers:<yourprovider>.DefaultDictionary="
  • LocalizeDictionary:
        private LocalizeDictionary()
        {
#if WINDOWS_PHONE
            this.DefaultProvider = StaticResxLocalizationProvider.Instance;
#else
            this.DefaultProvider = <yourprovider>.Instance;
#endif
            this.SetCultureCommand = new CultureInfoDelegateCommand(SetCulture);
        }
and
        public bool ResourceKeyExists(string resourceAssembly, string resourceDictionary, string resourceKey, CultureInfo cultureToUse)
        {
#if WINDOWS_PHONE
            var provider = StaticResxLocalizationProvider.Instance;
#else
            var provider = <yourprovider>.Instance;
#endif
            return ResourceKeyExists(resourceAssembly + ":" + resourceDictionary + ":" + resourceKey, cultureToUse, provider);
        }
  • LocExtension:
        [EditorBrowsable(EditorBrowsableState.Never)]
        public string ResourceIdentifierKey
        {
            get { return string.Format("{0}:{1}:{2}", assembly, dict, key ?? "(null)"); }
            set { <yourprovider>.ParseKey(value, out assembly, out dict, out key); }
        }
There are still some improvements that I noticed and can be added to the todo list:
  • Cleaning the unused code taken from the Resx provider for CSV providers
  • Fix the issue with the dot notation for the CSVEmbeddedLocalizationProvider
  • Be able to easily switch between providers without changing the provider name in all the files
Kormyr
Coordinator
May 6, 2013 at 9:41 PM
Hi,

I've pulled your results and began working on it regarding your improvement suggestions.
Thank you for your contribution.

Best regards,
Uwe
May 6, 2013 at 9:53 PM
Hi,

Thanks, let me know if you need precisions.

Regards,

Kormyr
May 8, 2013 at 6:46 AM
Hello,
I was trying to use the CSV example but i have some errors. Could you give more details how to integrate the CSV provider in a sample application?

Thanks,
Dan
May 8, 2013 at 8:48 AM
Edited May 8, 2013 at 1:13 PM
Hi,

No problem, so you have 2 providers, here is how to use them:

CSVLocalizationProvider:
  • Replace all occurrences of the ResxLocalizationProvider like explained in my post.
  • Add a "Localization" folder in your project.
  • Add CSV files in this folder and name them like this: <dictionary>.<culture>.csv.
  • Set copy to output directory to true
  • Having the CSV files in the same assembly is not mandatory, what is really important is to have the "Localization" folder and the CSV files in the execution folder.
CSVEmbeddedLocalizationProvider:
  • Replace all occurrences of the ResxLocalizationProvider like explained in my post.
  • Add CSV files named like this: <dictionary>-<culture>.csv.
  • Set their build action as Embedded Resource
  • You can put the CSV files in a "Localization" folder but it's not mandatory, they will be searched by reflection.
I used both syntaxes with the 2 providers:
  • {lex:LocText <key>} with Providers:CSVEmbeddedLocalizationProvider.DefaultAssembly="<assembly>" and Providers:CSVEmbeddedLocalizationProvider.DefaultDictionary="<dictionary>" in the attributes.
  • {lex:LocText <assembly>:<dictionary>:<key>}
EDIT: I thought you were a contributor to the WPF Localization Extension. I had also some troubles with the CSV provider example.
Another CSV provider may be included as I described (as you can see in the discussion), with the ability to embed or not the CSV files. Just wait for the next release. If you can't wait, I can send you the CSV provider files if you want.

Regards,
Kormyr
Coordinator
May 16, 2013 at 8:52 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.