mui icon indicating copy to clipboard operation
mui copied to clipboard

How to localize YesNo buttons of a ModernDialog

Open 4gn3s opened this issue 9 years ago • 7 comments

Hi, I have the following lines in my MainWindow constructor:

Thread.CurrentThread.CurrentCulture = new CultureInfo("pl-PL");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("pl-PL");
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

However, when using

ModernDialog.ShowMessage("test text", "test title", MessageBoxButton.YesNo)

the YES and NO buttons are still in English- is it possible to translate those?

(When using a simple MessageBox.Show() instead, the buttons are translated fine)

4gn3s avatar Oct 09 '15 10:10 4gn3s

Hm. I just added resource file for my language: 8zx73 and localization worked.

Dvornik avatar Mar 15 '16 21:03 Dvornik

Where goes the resource file? Can you give me an example?

SuricateCan avatar Jun 07 '16 22:06 SuricateCan

A ressource file is here. It's named Resources.$LANGUAGE_CODE.resx

Copy Resources.resx as a file with the language you need, then edit the content, not the name, of the strings.

sylveon avatar Jun 07 '16 22:06 sylveon

I did that, but I must be doing something wrong. The buttons still have the original language.

I have created a resources file on the root of my application (tried with it on the Properties folder as well) and named Resources.pt.resx (tried Resources.pt-BR.resx too).

I've tried also forcing the culture of my application with the following code with no success:

var cultureInfo = new CultureInfo("pt-BR");

            // Assigning our custom Culture to the application.                        
            Thread.CurrentThread.CurrentCulture = cultureInfo;
            Thread.CurrentThread.CurrentUICulture = cultureInfo;

            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
            new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

Here is my resource file:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <!-- 
    Microsoft ResX Schema 
    ...
   -->
  <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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <resheader name="writer">
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <data name="Back" xml:space="preserve">
    <value>Voltar</value>
  </data>
  <data name="Cancel" xml:space="preserve">
    <value>Cancelar</value>
  </data>
  <data name="Close" xml:space="preserve">
    <value>Fechar</value>
  </data>
  <data name="Maximize" xml:space="preserve">
    <value>Maximizar</value>
  </data>
  <data name="Minimize" xml:space="preserve">
    <value>Minimizar</value>
  </data>
  <data name="NavigateLink" xml:space="preserve">
    <value>Link de Navegação</value>
  </data>
  <data name="NavigationFailed" xml:space="preserve">
    <value>Falha na Navegação</value>
  </data>
  <data name="NavigationFailedFrameNotFound" xml:space="preserve">
    <value>Não foi possível navegar para {0}, um ModernFrame alvo não foi encontrado '{1}'</value>
  </data>
  <data name="NavigationFailedSourceNotSpecified" xml:space="preserve">
    <value>Não foi possível navegar para {0}, nenhuma fonte especificada</value>
  </data>
  <data name="No" xml:space="preserve">
    <value>Não</value>
  </data>
  <data name="Ok" xml:space="preserve">
    <value>Ok</value>
  </data>
  <data name="Restore" xml:space="preserve">
    <value>Restaurar</value>
  </data>
  <data name="UIThreadRequired" xml:space="preserve">
    <value>A operação requer uma thread the UI</value>
  </data>
  <data name="UnexpectedToken" xml:space="preserve">
    <value>Token inesperado</value>
  </data>
  <data name="UnknownOS" xml:space="preserve">
    <value>Sistema operacional desconhecido</value>
  </data>
  <data name="UnknownTokenType" xml:space="preserve">
    <value>Tipo do token desconhecido</value>
  </data>
  <data name="Yes" xml:space="preserve">
    <value>Sim</value>
  </data>
</root>

SuricateCan avatar Jun 07 '16 22:06 SuricateCan

For now, you can't add ressources to MUI without having to manually compile it for your project or add a PR here.

sylveon avatar Jun 07 '16 22:06 sylveon

@charlesmilette Oh, that is the reason... It is unfortunate.

Its not just about the localization, but also the "lowercase" buttons.

But thanks, I'll compile the project with my localization.

If I figure a way of including a feature like this I'll post a PR.

SuricateCan avatar Jun 07 '16 22:06 SuricateCan

put it wherever you want in your solution, remove the reference to the original, then add your dll as a reference.

sylveon avatar Jun 08 '16 01:06 sylveon