Working with Sources C#?

Asked

Viewed 95 times

4

I added the Dictionary Source to my project, now I need to convert it into a code dictionary, but it is bringing the null resource, someone can 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 to Resource.

  • On what line or lines is this happening?

  • 1

    The moment I’m giving GetManifestResouceStream

  • The name of tx_spell_open_dict_resource.pt_BR.dic would be tx_spell_open_dict_resource.pt_BR.dic.resx?

  • Take a look at https://stackoverflow.com/questions/10726857/why-does-getmanifestresourcestream-returns-null-while-the-resource-name-exists-w

  • I took a look , but unfortunately that’s not the problem. I tried to rename with the namespace, even so it return null.

1 answer

2


Verin,

I use it as follows.

I create a file named Resources.resx in Properties. Then I create the files with the names Resources.en-BR.resx, Resources.en-US.resx and so on.

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

To translate specific texts I use this function:

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

At the entry of the Basecontroller class (here I use MVC).

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

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.