Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    App_localResources per sito multilingua

    Ciao
    Sto cercando di fare il mio primo sito in asp.net e volevo crearlo con funzionalità multilingua usando App_localResources. Ho una master page (MasterPage.master) il cui titolo della pagina dovrebbe cambiare a seconda della lingua del browser:
    <title>
    <asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:title %>"></asp:Literal>
    </title>

    Quindi nella cartella App_localResources/MasterPage.master ho creato i file MasterPage.master.it.resx MasterPage.master.en.resx e MasterPage.master.resx, aggiungendo in fondo al codice:
    <data name="title">
    <value>Sito in Italiano</value>
    </data>

    o Sito in inglese a seconda della lingua

    Pubblico tutta la pagina asterPage.master.it.resx:
    <?xml version="1.0" encoding="utf-8"?>
    <root>
    <!--
    Microsoft ResX Schema

    Version 2.0

    The primary goals of this format is to allow a simple XML format
    that is mostly human readable. The generation and parsing of the
    various data types are done through the TypeConverter classes
    associated with the data types.

    Example:

    ... ado.net/XML headers & schema ...
    <resheader name="resmimetype">text/microsoft-resx</resheader>
    <resheader name="version">2.0</resheader>
    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
    <value>[base64 mime encoded serialized .NET Framework object]</value>
    </data>
    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
    <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
    <comment>This is a comment</comment>
    </data>

    There are any number of "resheader" rows that contain simple
    name/value pairs.

    Each data row contains a name, and value. The row also contains a
    type or mimetype. Type corresponds to a .NET class that support
    text/value conversion through the TypeConverter architecture.
    Classes that don't support this are serialized and stored with the
    mimetype set.

    The mimetype is used for serialized objects, and tells the
    ResXResourceReader how to depersist the object. This is currently not
    extensible. For a given mimetype the value must be set accordingly:

    Note - application/x-microsoft.net.object.binary.base64 is the format
    that the ResXResourceWriter will generate, however the reader can
    read any of the formats listed below.

    mimetype: application/x-microsoft.net.object.binary.base64
    value : The object must be serialized with
    : System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter
    : and then encoded with base64 encoding.

    mimetype: application/x-microsoft.net.object.soap.base64
    value : The object must be serialized with
    : System.Runtime.Serialization.Formatters.Soap.SoapF ormatter
    : and then encoded with base64 encoding.

    mimetype: application/x-microsoft.net.object.bytearray.base64
    value : The object must be serialized into a byte array
    : using a System.ComponentModel.TypeConverter
    : and then encoded with base64 encoding.
    -->
    <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
    <xsd:element name="root" msdata:IsDataSet="true">
    <xsd:complexType>
    <xsd:choice maxOccurs="unbounded">
    <xsd:element name="metadata">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="value" type="xsd:string" minOccurs="0" />
    </xsd:sequence>
    <xsd:attribute name="name" use="required" type="xsd:string" />
    <xsd:attribute name="type" type="xsd:string" />
    <xsd:attribute name="mimetype" type="xsd:string" />
    <xsd:attribute ref="xml:space" />
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="assembly">
    <xsd:complexType>
    <xsd:attribute name="alias" type="xsd:string" />
    <xsd:attribute name="name" type="xsd:string" />
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="data">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
    <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
    </xsd:sequence>
    <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
    <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
    <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
    <xsd:attribute ref="xml:space" />
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="resheader">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
    </xsd:sequence>
    <xsd:attribute name="name" type="xsd:string" use="required" />
    </xsd:complexType>
    </xsd:element>
    </xsd:choice>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    <resheader name="resmimetype">
    <value>text/microsoft-resx</value>
    </resheader>
    <resheader name="version">
    <value>2.0</value>
    </resheader>
    <resheader name="reader">
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>
    <resheader name="writer">
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    </resheader>
    <data name="title">
    <value>Sito in Italiano</value>
    </data>

    </root>
    Di fatto quando pubblico il sito il browser trova la chiave (non mi da errori) ma anche se cambio la lingua del browser (anche in inglese en) continuo a vedere sempre il valore scritto nella pagina MasterPage.master.it.resx (Sito in italiano). Se provo a escludere il file MasterPage.master.it.resx e lasciando la lignua del browser in ihnglese vedo quella predefinita di default; e se levo anche quella mi da errore (non trova la chiave del valore) anche se c'è il fileMasterPage.master.en.resx. Cosa devo cambiare? Spero di essere stato chiaro ho scrito di fretta. Grazie in anticipo a tutti

  2. #2
    Sono riuscito a risolvere il problema mettendo <globalization uiCulture="en" culture="en-UK" />, ma vorrei cambiare la lingua runtime e quindi il problema rimane... Oltretutto uso una masterpage e quindi non posso fare
    protected override void InitializeCulture(object sender, EventArgs e)
    {

    string culture = "en-GB";
    if (string.IsNullOrEmpty(culture)) culture = "Auto";
    if (culture != "Auto")
    {
    System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(culture);
    System.Threading.Thread.CurrentThread.CurrentCultu re = ci;
    System.Threading.Thread.CurrentThread.CurrentUICul ture = ci;
    }
    perché la masterPage non fa l'override della funzione...

    Qualcuno sa linkarmi qualche sito che spieghi ammodo come usare App_localResources?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.