本土化与.NET精简框架 [英] localization with .net compact framework

查看:235
本文介绍了本土化与.NET精简框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发用于移动设备(Windows CE 5.0中,.NET紧凑framwork 2.0预安装),使用.NET精简框架3.5和微软的Visual Studio 2008中。

I'm developing an application for mobile devices (Windows CE 5.0, .NET compact framwork 2.0 pre-installed) using .NET compact framework 3.5 and MS Visual Studio 2008.

我使用的是内置选项创建本地化的表单。这只要完美,因为我使用Visual Studio的调试功能与连接到我的台式电脑,移动设备的工作原理。在这种情况下,Visual Studio的部署与我的.NET Compact Framework 3.5的应用程序一起。 。断开移动设备和具有安装我的应用程序如预期仍能工作后

I'm using the built-in option for creating localized forms. This works perfectly as long as I use the debugging function of Visual Studio with the mobile device connected to my desktop computer. In this case, Visual Studio deploys my application along with .NET compact framework 3.5. After disconnecting the mobile device and having installed my application it is still working as expected.

我的问题是:如果我安装使用所提供的CAB文件.NET Compact Framework的微软再安装我的应用程序(也可以通过使用Visual Studio创建CAB文件),而不必使用的应用程序的工作原理以及但是没有国产化调试器。因此,我认为必须有.NET框架的某些部分,它们只能通过安装Visual Studio的部署功能 - 而这些都使得.NET识别的语言环境。 - (库...)是否有人知道哪些部分是这些?由于应用程序将提供给我已经找到了一个解决方案,将不使用Visual Studio的用户。

My problem is: If I install the .NET compact framework using the CAB file provided by Microsoft and then install my application (also by using the CAB file created by Visual Studio) without having used the debugger the application works as well but without localization. So I think there must be some parts of the .NET framework which are only installed using the deployment function of Visual Studio - and which are making .net recognizing the locale. - Does anybody know which parts (libraries...?) are these? Since the application will be provided to users which will not use Visual Studio I've to find a solution for this.

推荐答案

的答案很简单。它应该工作。但事实并非如此。

The answer is simple. It should work. But it does not.

有显然是微软的工具CABWiz使用由Visual Studio生成CAB文件的错误。它在不同的子文件夹使用相同名称的文件时,使用本地化的时候像有问题。

There is clearly a bug in Microsoft's tool CABWiz used by Visual Studio to generate CAB files. It has a problem when using files with the same name in different subfolders, like when using localizations.

在试图修复它时,我结束了蒙山通过的 CodeProject上的指南由山茱萸在以前的答案给定的:你有黑客生成的Visual Studio的过程CAB,通过使用资源文件具有独特的名称,然后修改INF文件,在设备上部署指定原始名称。

After hours of trying to fix it, I ended up whith a solution inspired by the CodeProject guide as given by Cornel in the previous answer : You have to "hack" the Visual Studio process of generating CAB, by using resource files with unique name, and then modifying the INF file to specify the original name for deployment on the device.

要使自动化多一点,我做了启动作为项目生成后一点EXE:

To automatize a little more, I made a little EXE that is launched as project post-build :

        FileInfo CurrentExeInfo = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);

        // Current Folder + bin\Debug
        DirectoryInfo BinDebug = new DirectoryInfo( Path.Combine( CurrentExeInfo.Directory.FullName,  @"bin\Debug") );

        // Subfolders in \bin\Debug
        Console.WriteLine(BinDebug.FullName);
        string[] Dirs = Directory.GetDirectories(BinDebug.FullName, "*", SearchOption.TopDirectoryOnly);

        // In each localization folder ...
        foreach (string Dir in Dirs)
        {
            DirectoryInfo DirInfo = new DirectoryInfo(Dir);

            // ... Resource files
            string[] RFiles = Directory.GetFiles(Dir, "*.resources.dll");

            foreach (string RFile in RFiles)
            {
                FileInfo RFileInfo = new FileInfo(RFile);
                bool DoCopy = false;

                // No underscore in resource name
                if (!RFileInfo.Name.Contains("_") || RFileInfo.Name.IndexOf("_") == 0)
                {
                    DoCopy = true;
                }
                // underscore in resource name
                // --> Have to check if already a copy 
                else
                { 
                    // prefix removal
                    int PrefixIndex = RFileInfo.Name.IndexOf("_");
                    string TestFilename = RFileInfo.Name.Substring(PrefixIndex + 1);

                    if (!File.Exists(Path.Combine(Dir, TestFilename)))
                    {
                        // File without underscore does not exist, so must copy
                        DoCopy = true;
                    }
                }

                if (DoCopy)
                {
                    // Copy file
                    string NewFileName = Path.Combine(Dir, DirInfo.Name.ToUpper() + "_" + RFileInfo.Name);
                    Console.WriteLine("Copying " + RFile + " -> " + NewFileName);
                    File.Copy(RFile, NewFileName, true);
                }
            }
        }

和则该CAB补丁后正常CAB代:

And then this CAB patcher after normal CAB generation :

    const string cabwizpath = @"C:\Program Files (x86)\Microsoft Visual Studio 9.0\SmartDevices\SDK\SDKTools\cabwiz.exe";

    static void Main(string[] args)
    {
        if (args.Length == 0)
        {
            Console.WriteLine("Aborted: You must enter the inf file information");
            Console.ReadLine();
            return;
        }
        if (!File.Exists(args[0]))
        {
            Console.WriteLine("Aborted: I can not found the INF file!");
            Console.ReadLine();
            return;
        }

        // string to search
        Regex R = new Regex("\"[A-Z]{2,3}_(.+)\\.resources\\.dll\",\"([A-Z]{2,3})_(.+)\\.resources\\.dll\"");

        // File reading
        string inffile = File.ReadAllText(args[0]);

        // Format replace from
        // "FR_ProjectName.resources.dll","FR_ProjectName.resources.dll"
        // To
        // "ProjectName.resources.dll","FR_ProjectName.resources.dll"
        inffile = R.Replace(inffile, "\"$1.resources.dll\",\"$2_$3.resources.dll\"");

        // Rewriting file
        File.WriteAllText(args[0], inffile);
        Console.WriteLine("INF file patched ...");

        // Génération du CAB ...
        Console.WriteLine("Generating correct CAB ... ");
        System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo("\"" + cabwizpath + "\"", "\"" + args[0] + "\"");
        proc.ErrorDialog = true;
        proc.UseShellExecute = false;
        proc.RedirectStandardOutput = true;
        Process CabWiz =  Process.Start(proc);
        Console.WriteLine("\""+cabwizpath + "\" \""+ args[0]+"\"");
        CabWiz.WaitForExit();
        Console.WriteLine("CAB file generated (" + CabWiz.ExitCode + ") !");
    }



我希望它能帮助。

I hope it helps.

有关这方面更多的链接:

More links about this :

  • culture specific string resource dll not working in .net compact framework when application is installed using cab file
  • https://social.msdn.microsoft.com/Forums/fr-FR/0fbcc5b0-a6ff-4236-961d-22c5f17ed2e7/smart-device-cab-project-includes-wrong-localized-resources

这篇关于本土化与.NET精简框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆