Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Localization based on namespace

Localization based on namespace

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpvisual-studiolearningregexhelp
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Moreno Airoldi
    wrote on last edited by
    #1

    Hey guys recently I've been wondering about which would be the best way to implement a localization system based on namespaces. Let's say that for some reason I wanted to use a few source code files in many different projects, and for some other reason I don't want or cannot build a DLL out of them (which of course would be the "right" way to do this). Let's also say I need to localize that code in a few different languages. Also, the files I'll be sharing all use the same namespace. Now, the standard localization technique in Visual Studio works real fine and is very easy to maintain and update within the IDE, but it's all tied to the project's main assembly name. So, while I could just copy and paste over all the necessary localization strings for my shared files each time, and prefix all the relevant localized string names with my namespace ID, that would be clumsy and error prone. I was wondering if there was a way to build up some DLL or resource files and just bundle them up with the source code to be shared. I've been considering for example building up a few resource files within the IDE, using file names that include the namespace and the different culture IDs, and then implementing a custom resource manager using ResXResourceReader or something similar. Any other ideas ? :) P.S.: we are talking C# here.

    In theory, there is no difference between theory and practice, but not in practice. - Anonymous A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match. - B. Bryson

    B L J 3 Replies Last reply
    0
    • M Moreno Airoldi

      Hey guys recently I've been wondering about which would be the best way to implement a localization system based on namespaces. Let's say that for some reason I wanted to use a few source code files in many different projects, and for some other reason I don't want or cannot build a DLL out of them (which of course would be the "right" way to do this). Let's also say I need to localize that code in a few different languages. Also, the files I'll be sharing all use the same namespace. Now, the standard localization technique in Visual Studio works real fine and is very easy to maintain and update within the IDE, but it's all tied to the project's main assembly name. So, while I could just copy and paste over all the necessary localization strings for my shared files each time, and prefix all the relevant localized string names with my namespace ID, that would be clumsy and error prone. I was wondering if there was a way to build up some DLL or resource files and just bundle them up with the source code to be shared. I've been considering for example building up a few resource files within the IDE, using file names that include the namespace and the different culture IDs, and then implementing a custom resource manager using ResXResourceReader or something similar. Any other ideas ? :) P.S.: we are talking C# here.

      In theory, there is no difference between theory and practice, but not in practice. - Anonymous A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match. - B. Bryson

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      You are trying a really weird way of code re-use. In my opinion, you have to update your tool which you use for your current code sharing such that it can handle the resources also.

      M 1 Reply Last reply
      0
      • M Moreno Airoldi

        Hey guys recently I've been wondering about which would be the best way to implement a localization system based on namespaces. Let's say that for some reason I wanted to use a few source code files in many different projects, and for some other reason I don't want or cannot build a DLL out of them (which of course would be the "right" way to do this). Let's also say I need to localize that code in a few different languages. Also, the files I'll be sharing all use the same namespace. Now, the standard localization technique in Visual Studio works real fine and is very easy to maintain and update within the IDE, but it's all tied to the project's main assembly name. So, while I could just copy and paste over all the necessary localization strings for my shared files each time, and prefix all the relevant localized string names with my namespace ID, that would be clumsy and error prone. I was wondering if there was a way to build up some DLL or resource files and just bundle them up with the source code to be shared. I've been considering for example building up a few resource files within the IDE, using file names that include the namespace and the different culture IDs, and then implementing a custom resource manager using ResXResourceReader or something similar. Any other ideas ? :) P.S.: we are talking C# here.

        In theory, there is no difference between theory and practice, but not in practice. - Anonymous A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match. - B. Bryson

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Moreno Airoldi wrote:

        but it's all tied to the project's main assembly name

        How so? You can add a *.res file to a project, and name it as you like. You can then add resources there. You could name it after your class, having a *.cs and .res file for it (and optionally a .xaml/.cs.Designer file).

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        M 1 Reply Last reply
        0
        • M Moreno Airoldi

          Hey guys recently I've been wondering about which would be the best way to implement a localization system based on namespaces. Let's say that for some reason I wanted to use a few source code files in many different projects, and for some other reason I don't want or cannot build a DLL out of them (which of course would be the "right" way to do this). Let's also say I need to localize that code in a few different languages. Also, the files I'll be sharing all use the same namespace. Now, the standard localization technique in Visual Studio works real fine and is very easy to maintain and update within the IDE, but it's all tied to the project's main assembly name. So, while I could just copy and paste over all the necessary localization strings for my shared files each time, and prefix all the relevant localized string names with my namespace ID, that would be clumsy and error prone. I was wondering if there was a way to build up some DLL or resource files and just bundle them up with the source code to be shared. I've been considering for example building up a few resource files within the IDE, using file names that include the namespace and the different culture IDs, and then implementing a custom resource manager using ResXResourceReader or something similar. Any other ideas ? :) P.S.: we are talking C# here.

          In theory, there is no difference between theory and practice, but not in practice. - Anonymous A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match. - B. Bryson

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          Moreno Airoldi wrote:

          but it's all tied to the project's main assembly name

          I kind of doubt that. I would suspect that although that is one way to use it there are others.

          Moreno Airoldi wrote:

          Let's also say I need to localize that code in a few different languages.

          You don't localize code - you localize applications. There will be differences otherwise little point in having different applications. If you have common blocks that need to be translated then keep them in their own files and then, if necessary, write a tool that merges them in the build process as a pre-build step.

          L M 2 Replies Last reply
          0
          • J jschell

            Moreno Airoldi wrote:

            but it's all tied to the project's main assembly name

            I kind of doubt that. I would suspect that although that is one way to use it there are others.

            Moreno Airoldi wrote:

            Let's also say I need to localize that code in a few different languages.

            You don't localize code - you localize applications. There will be differences otherwise little point in having different applications. If you have common blocks that need to be translated then keep them in their own files and then, if necessary, write a tool that merges them in the build process as a pre-build step.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            jschell wrote:

            You don't localize code - you localize applications.

            "Or components thereof".

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            1 Reply Last reply
            0
            • B Bernhard Hiller

              You are trying a really weird way of code re-use. In my opinion, you have to update your tool which you use for your current code sharing such that it can handle the resources also.

              M Offline
              M Offline
              Moreno Airoldi
              wrote on last edited by
              #6

              I'm not discussing the way to re-use code here. As I said, I'm perfectly aware the "right" way to do this is by using DLLs to share code. I'll take your answer as "I don't think what you propose can/should be done". :)

              In theory, there is no difference between theory and practice, but not in practice. - Anonymous A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match. - B. Bryson

              1 Reply Last reply
              0
              • L Lost User

                Moreno Airoldi wrote:

                but it's all tied to the project's main assembly name

                How so? You can add a *.res file to a project, and name it as you like. You can then add resources there. You could name it after your class, having a *.cs and .res file for it (and optionally a .xaml/.cs.Designer file).

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                M Offline
                M Offline
                Moreno Airoldi
                wrote on last edited by
                #7

                Of course you can andd a .res file to a project and name it as you like. What I'm asking is a whole different thing. I'll try to be more specific. :) In a Visual Studio solution, the standard way to add localization is by creating a set of resource files named "Localization" plus the culture ID. So for example you will have "localization.resx", "Localization.it.resx", "Localization.de.resx" for your default language, Italian and German, and so on. Then, you can use a ResourceManager to get your localized strings:

                ResourceManager LocalizationResourceManager = new ResourceManager(Assembly.GetExecutingAssembly().GetName().Name + ".Localization", Assembly.GetExecutingAssembly());
                ...
                string LocalizedString = LocalizationResourceManager.GetString(ResourceName, Culture);

                Now this is perfectly fine and of course does not stop me from doing what I need to, even if I share code by copying over source files. But as you see clearly in the ResourceManager constructor, it's tied to the assembly name, simply because the resource file is compiled together with the project's main assembly. I was simply wondering if there was a way to somehow change this so that the DLLs compiled from the resource files will be tied to a different namespace. What I'm asking basically is: can I have VS compile a resource file in a project and not automatically assign the resources to the project's main namespace ? Hope it's more clear now. :) EDIT: Just to be even more clear - nothing stops me from naming my resource files "Localization_MYNAMESPACE" or something similar, that's actually what I would most likely do (haven't actually tried this but I'm pretty sure there is no reason why it should not work). I'm just wondering if there are different approaches, and found it quite interesting to investigate how one can configure the way the compiler acts on resource files.

                In theory, there is no difference between theory and practice, but not in practice. - Anonymous A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match. - B. Bryson

                1 Reply Last reply
                0
                • J jschell

                  Moreno Airoldi wrote:

                  but it's all tied to the project's main assembly name

                  I kind of doubt that. I would suspect that although that is one way to use it there are others.

                  Moreno Airoldi wrote:

                  Let's also say I need to localize that code in a few different languages.

                  You don't localize code - you localize applications. There will be differences otherwise little point in having different applications. If you have common blocks that need to be translated then keep them in their own files and then, if necessary, write a tool that merges them in the build process as a pre-build step.

                  M Offline
                  M Offline
                  Moreno Airoldi
                  wrote on last edited by
                  #8

                  jschell wrote:

                  write a tool that merges them in the build process as a pre-build step

                  You kind of put the finger on exactly what I was thinking of. :thumbsup: However, it's most likely not worth it to develop a specific tool for that, since it would still be easier to manage the localized resources semi-manually instead of having to keep the tool up to date and so on. :)

                  In theory, there is no difference between theory and practice, but not in practice. - Anonymous A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match. - B. Bryson

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups