Search code examples
c#.netresource-files

Resource Files how to name them?


I am playing around with resource files and have run into a problem.

I have a folder called Languages. When I make a resource file and say call it "R.resx" I can call this resource file up in my classes.

If I rename this file(or delete and make a new resource file) and call it R.en.resx I cannot call this resource file up in my class anymore.

Does the first language need to be in R.resx where the rest would be R.language.resx?


Solution

  • Step 6

    To create resource files for additional languages, copy the file in Solution Explorer or in Windows Explorer, and then rename it using one of the following patterns:

    For global resource files:
    
    name.language.resx
    
    name.language-culture.resx
    
    For local resource files:
    
    pageOrControlName.extension.language.resx
    
    pageOrControlName.extension.language-culture.resx
    

    So yes, you are correct in your assumption that the base resource file would be the first language.

    EDIT:

    var temp = Properties.Resources.ResourceManager.BaseName.Replace("YourNamespace.Properties.",""); 
    

    You may have to also do this (to get rid of the language part after the name chunk):

     temp = temp.Replace(".thelanguagechunk","");
    

    This code would get you the "name" chunk you are after by itself.