Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

localization issue 1

Status
Not open for further replies.

TipGiver

Programmer
Joined
Sep 1, 2005
Messages
1,863
hi,

i have pressed the 'show all files' in the solution explorer and i have a file called 'myform.it-IT.resx'. Everything runs ok, and localizations works after i change the culture and then show the form 'myform'.
(name: lblSomething.Text and value Hello... will have effect in the label)

Question: how can i localize a string variable in that .resx file? So, when writting messagebox.show(strString) .. the strString to have the new italian text?

I have tried but no luck:
$this.strString
>>$this.strString
strString

Thank you.
 
That particular .resx file is for that form. If you want a more generic way to have globalized text, add a new resource file to your project, and then create a class to access it.

In the shared constructor, Get the executing assembly (Assembly.GetExecutingAssembly), then instantiate a shared instance of a ResourceManager. The trick is that the 1st parameter to the ResourceManager constructor is the name of the resource file, with the project name prepended:
Code:
MyProject.MyResourceFile
It's case-sensitive.

Afterwards, create static properties and functions that get values out of the resource file, using the GetString method of the ResourceManager instance.

Note that you can store format strings in the resource file, so if you need to insert a parameter, you can do it easily with the String.Format() call.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
hello chip,

can't i do the same with the form's .resx file?
 
Here is what i have:
- I have a file called 'Resource1.en-US.resx' in the project (not in the solution)
- the following code.

Code:
imports System.Reflection

Public Class Class1

    Private Shared rm As Resources.ResourceManager


    Shared Sub New()

        Dim ea As [Assembly] = [Assembly].GetEntryAssembly()
        rm = New Resources.ResourceManager("Resource1", ea)
    End Sub


    Public Shared ReadOnly Property x() As String
        Get
            Return rm.GetString("xxx")
        End Get

    End Property

End Class

Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-US")
        MsgBox(Class1.x)
    End Sub


The error i get is:
Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "Resource1.resources" was correctly embedded or linked into assembly "WindowsApplication2".

What is wrong :(
 
rm = New Resources.ResourceManager("Resource1", ea)
The first parameter is incorrect. You must include the project name too {re-read my message above!}.

The resource files that are associated with the forms are just for those forms. They aren't intended for general use. Just create a new one & add it to the project.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Yes,

I had figured that ou some hours ago... and now i got the time to post back (saying that i forgot the "WindowsApplication1.") ..

Tnx

_________
So, these files are better to be used to localize strings, and the ones that are generated automatically as i change the form's language... just for the UI
Right?
 
So, these files are better to be used to localize strings, and the ones that are generated automatically as i change the form's language... just for the UI
Right?

Right. The resx files that are associated with the form are there for when you change the Language property.

If you were going to localize your app, you would send the resx files from your forms, plus any other resx files (like for strings, audio resources, etc) to the localization specialists.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
localization specialists.

You mean the translaters?

BTW, the only drawback (for me to big to ignore) is the fact that they need to restart the app to change the language.

Christiaan Baes
Belgium

"My new site" - Me
 
Hello!
I am back to this .. again :(

I have 2 projects in a solution. One is a class library and that project has the .resx files.

Code:
Imports System.Reflection

Public Class Class1
    Private Shared rm As Resources.ResourceManager


    Shared Sub New()
        Dim ea As [Assembly] = [Assembly].GetEntryAssembly
        rm = New Resources.ResourceManager(" ??? localdata", ea)
    End Sub



    Public Shared Function getLocal(ByVal name As String) As String
        Return (rm.GetString(name))
    End Function
End Class

The second project is the exe.
Note that i have cleared from both project the root namespace.

The error is:

An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll

Additional information: Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "Class1.localdata.resources" was correctly embedded or linked into assembly "WindowsApplication1".
baseName: Class1.localdata locationInfo: <null> resource file name: Class1.localdata.resources assembly: WindowsApplication1, Version=1.0.2549.2686, Culture=neutral, PublicKeyToken=null


I try to do this:

Code:
        Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-UK")

        MsgBox(Class1.getLocal("WrongPass"))


Can anyone help me? Thank in advance
 
chrissie1 said:
You mean the translaters?
There's more to it that just text translation -- you often have to "translate" images as well. For example, showing a US style mailbox doesn't work in Europe. Instead of a mostly-round box on a pole by the street, theirs are square, and attached to the house by the front door.

There are other cultural issues, too. Showing a woman in a dominant position relative to male colleagues doesn't work in Muslim countries (like, if she were leading a meeting).

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
TipGiver - I think the problem is that you're using GetEntryAssembly to load your resources. Since the current project is a library assembly, and can't be run directly, this means it will try & load them from the assembly that the process was started with (your EXE). Use GetExecutingAssembly instead.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
!! Thanks again

I think this combination is what i missed. I had done many many tries (choosing also the calling assembly) + the fact that it was tricky enough, as the root namespace was clear but i had nested namespaces.

It appears that only the root namespace is important.

Thanks and Merry Xmas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top