Question

I have the following code in a User Control called View.ascx:

<label><asp:Label ID="lblProvince" runat="server" ResourceKey="lblProvince"></asp:Label>:</label>
<asp:DropDownList ID="PROVINCE" runat="server">
    <asp:ListItem ResourceKey="liselectprovince"></asp:ListItem>
    <asp:ListItem Value="ab" ResourceKey="liab"></asp:ListItem>
    <asp:ListItem Value="bc" ResourceKey="libc"></asp:ListItem>
    <asp:ListItem Value="mb" ResourceKey="limb"></asp:ListItem>
    <asp:ListItem Value="nb" ResourceKey="linb"></asp:ListItem>
    <asp:ListItem Value="nf" ResourceKey="linf"></asp:ListItem>
    <asp:ListItem Value="ns" ResourceKey="lins"></asp:ListItem>
    <asp:ListItem Value="nt" ResourceKey="lint"></asp:ListItem>
    <asp:ListItem Value="nu" ResourceKey="linu"></asp:ListItem>
    <asp:ListItem Value="on" ResourceKey="lion"></asp:ListItem>
    <asp:ListItem Value="pi" ResourceKey="lipi"></asp:ListItem>
    <asp:ListItem Value="qb" ResourceKey="liqb"></asp:ListItem>
    <asp:ListItem Value="sk" ResourceKey="lisk"></asp:ListItem>
    <asp:ListItem Value="yk" ResourceKey="liyk"></asp:ListItem>
</asp:DropDownList>

The ResourceKey maps to values found in files View.ascx.fr-CA.resx and View.ascx.resx.

I do not have access to the any other code on the server. I can only do my work within a plugin of this greater software, which will embed any user control that I create.

The rest of hte site is being rendered as en-CA.

I tried to programmatically set culture from my user control like so:

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-CA");

But that doesn't force my view.ascx to use values from view.ascx.fr-CA.resx. Instead it still uses View.ascx.resx.

How can I write code that will select the appropriate resx file? I want to use view.ascx.resx on all pages with url that start with /en and view.ascx.fr-CA.resx on all pages with url that start with /fr .

Was it helpful?

Solution 2

I figured it out. I can do this:

Localization.SetThreadCultures(new System.Globalization.CultureInfo("fr-CA"), DotNetNuke.Entities.Portals.PortalSettings.Current);

I can replace fr-CA with any other language.

OTHER TIPS

This is not exctly what you need:

ResourceManager manager = new ResourceManager("Resources.Messages", Assembly.Load("App_GlobalResources"));
string test = manager.GetString("EmailBodyMagazine",new System.Globalization.CultureInfo("fr-CA"););

But maybe you can also use the resource manager to access your files directly

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top