Search code examples
asp.netlocalizationculture

asp.net localization question


I have two resource files: Resource1.resx and Resource1.es-mx.resx The default system culture is en-US.

  1. <%@ Page UICulture="es" Culture="es-MX" %> --> still get English version (setting language in the browser doesn't help).
  2. Rename Resource1.es-mx.resx to Resource1.es.resx --> works, Spanish.
  3. <%@ Page UICulture="auto" Culture="auto" %>, set Spanish in the browser, resource Resource1.es-mx.resx --> Spanish.

Could you explain to me what happens in the first case? Why English?


Solution

  • Why English? There are no Spanish country-neutral resources and you ask specifically for them. So it falls back to neutral resources (which happens to be English in your case).

    You should do that the other way round: name resources file Resource1.es.resx and ask for specific UICulture: UICulture="es-MX" if you have to. In such case, if country-specific resources are not found, it will fall back to Spanish country-neutral resources (es).
    I am not aware of your use case, but hard-coding cultures is not really good idea... You really should think about using auto here.