-->

Localized String with Interface Builder User Defin

2019-06-19 03:19发布

问题:

I am currently trying to create a localized accessibilityLabel in the storyboard (I am trying to avoid doing it programatically). It seems that whenever I use the Localized String option, the accessibilityLabels ends up being set to the localized string key that I have provided rather than the string itself. Does anyone have the solution to this problem? Any help would be greatly appreciated.

回答1:

I guess you expect the localized string to be taken from Localizable.strings. The "Localized String" type doesn't work this way, it's just a marker to indicate that the value of the user defined runtime attribute will participate in the localization process when you use base localization. Please take a look at https://stackoverflow.com/a/24527990/2876231 for a lengthier explanation.



回答2:

The attribute type needs to be Localizable String, and then you'd translate it in the .strings file using the following property:

"KLc-fp-ZVK.ibExternalUserDefinedRuntimeAttributesLocalizableStrings[0]" = "¡Hola!";

Unfortunately, it doesn't seem to work with a named attribute, but only with the long property above.

(Based on Andrew's answer here: Localize a view within a storyboard using "User Defined Runtime Attributes")