Localize a view within a storyboard using “User Defined Runtime Attributes”

前端 未结 3 1083
心在旅途
心在旅途 2021-01-04 08:43

I currently have a semi-automated way to localize my views. However, today I found an interesting section in IB, which seems to suggest that I can localize my views from wit

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-04 09:40

    The purpose of the "Localized String" type is to let you define a runtime attribute value that will participate in the localization process (using base localization). This is handy if for example you define a custom control, include it in the storyboard and want to assign a localizable string to one of its properties. However this only works on Mac OS, not on iOS.

    You can easily confirm this doing the following experiment: put a UILabel / NSTextField in your storyboard and set the "text" / "stringValue" property using a user defined runtime attribute. If you use "String" as the type of the attribute and generate the corresponding strings file you won't see it anywhere in the file. In contrast, if you change the type to "Localized String" and generate the strings file you will find an entry like this:

    /* Class = "IBUILabel"; wij-Kq-q92.ibExternalUserDefinedRuntimeAttributesLocalizableStrings[0] = "Localized value"; ObjectID = "wij-Kq-q92"; */
    "wij-Kq-q92.ibExternalUserDefinedRuntimeAttributesLocalizableStrings[0]" = "Localized value";
    

    Then you can localize this value in the corresponding language strings file. Again, this works on Mac OS, but not on iOS.

提交回复
热议问题