Working with C # resources?

4

I added the dictionary resource to my project, now I need to convert it to a dictionary via code, but it is bringing the null resource, can anyone help me?

List<string> dic = new List<string>();
List<string> aff = new List<string>();

Assembly _assembly;
StreamReader _textStreamReader;

_assembly = Assembly.GetExecutingAssembly();
string line;

_textStreamReader = new StreamReader(
    _assembly.GetManifestResourceStream("tx_spell_open_dict_resource.pt_BR.dic"));
while ((line = _textStreamReader.ReadLine()) != null)
{
    dic.Add(line);
}

_textStreamReader = new StreamReader(
    _assembly.GetManifestResourceStream("tx_spell_open_dict_resource.pt_BR.aff"));
while ((line = _textStreamReader.ReadLine()) != null)
{
    aff.Add(line);
}

OpenOfficeDictionary dic_ptBR = new OpenOfficeDictionary(
    dic.ToArray(), aff.ToArray(), new CultureInfo("pt_BR"));
txSpellChecker1.Dictionaries.Add(dic_ptBR);        

Maybe the wrong part is in the string that I try to get the resource.

    
asked by anonymous 08.08.2017 / 13:32

1 answer

2

Verin,

I use the following form.

I create a file named Resources.resx in Properties. Next I create the files named Resources.pt-BR.resx, Resources.en-US.resx and etc.

I create the same strings in the 3 files (or the other languages I need).

To translate specific texts I use this function that I put together:

    public static string Tradutor(string pVariavel)
    {
        try
        {
            ResourceManager rm = new ResourceManager(typeof(Resources));
            return rm.GetString(pVariavel);
        }
        catch
        {
            return "Variável não localizada.";
        }
    }

In the BaseController class entry (here I use MVC).

/*CULTUREINFO DO USUÁRIO*/
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("pt-BR");

The pt-BR call is for example only, you include it according to the form that stores this variable.

This is the simple way, aside from the other integrations, such as using in DataAnnotations within Views and etc.

    
08.08.2017 / 17:40