I have a ASP.NET multi-language application with 3 local resources for Hindi-English-Spanish.
The definitions for all the "xxxxResource1.Text" & "xxxxResource1.ToolTip" work just fine according to the primary language selected on the browser.
My question is if there is a way to handle the sizes of controls inside the same local resource file, I ask this because, as you can imagine, the translation of a word can have less or more characters than the english version. So I would like to do some adjustments to grid columns, textboxes, labels, etcetera if the application is viewed in another Language.
I wouldn't like to leave everything open by no defining the width of a button so it could addapt to the text shown on it, but rather prefer to be able to specify % or px values when required.
If Local Resources can not handle that kind of information about the controls, what would be a good approach to specify controls' sizes according to language?
PD. Actually the first time when I tried to set these values in Local Resource my first thought was to use "xxxxResource1.Width" but didn't work
Thanks in advance for any hint on this. Regards!
If you use the meta:resourcekey attribute, you can bind the control's properties to resources, which will automatically be applied to the control when it is rendered.
Well, sort of.
It only works for properties that are strings. So it works for Text
, Tooltip
, and CssClass
. But Width
isn't a string (it's a Unit
, whatever that is) and Style
, believe it or not, isn't a string either-- it's a sort of dictionary object.
My recommendation would be to define a few CSS classes for various widths and apply them along with the text.
Example button markup:
<asp:Button ID="Button1" runat="server" meta:resourcekey="Button1Resource1" Text="This actually gets ignored" />
Resx:
<data name="Button1Resource1.Text" xml:space="preserve">
<value>Localized text goes here</value>
</data>
<data name="Button1Resource1.CssClass" xml:space="preserve">
<value>Width120</value>
</data>
CSS:
.Width120 { width: 120px }
Not ideal, but simple enough. With maybe a dozen CSS classes you can cover a significant range of width possibilities.