11

Is it possible to add comment to a localized string in storyboard?

/* Class = "IBUILabel"; text = "Some text"; comment = "This is the comment to help translator" ObjectID = "0N3-up-Ts6"; */
"0N3-up-Ts6.text" = "Some text";
Thanh-Nhon Nguyen
  • 3,402
  • 3
  • 28
  • 41
JastinBall
  • 873
  • 8
  • 25

2 Answers2

8

It appears you can:

enter image description here

This produces:

/* Class = "UILabel"; text = "Title"; ObjectID = "KjJ-0v-J2z"; Note = "Comment for Localizer"; */
"KjJ-0v-J2z.text" = "Title";
jjrscott
  • 1,386
  • 12
  • 16
  • 1
    This is crashing Xcode 9 swift 4.... any workaround or reason on why this may be happening? https://stackoverflow.com/questions/46546563/xcode-9-crash-on-label-localizer-comment-edition – user805981 Oct 24 '17 at 01:31
  • 1
    This works properly on Xcode 9.4.1. Very useful to mark text that doesnt need translation with a tag for later processing. – Peterdk Jul 03 '18 at 14:23
1

You can add a user-defined attribute:

User-defined attribute in Xcode

It will appear thus in the XIB:

<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="s1b-V9-EN7">
  <rect key="frame" x="20" y="45" width="728" height="959"/>
  <subviews>
     <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" v
       <rect key="frame" x="215" y="688" width="92" height="21"/>
       // . . . . etc . . . . 
       <userDefinedRuntimeAttributes>
          <userDefinedRuntimeAttribute type="string" keyPath="localization_comment" value="&quot;Some text to help the translator">
       </userDefinedRuntimeAttributes>
     </label>
  </subviews>
</view>
tooluser
  • 1,481
  • 15
  • 21
  • 2
    Will it appear in the .strings file? – Mabedan Jul 08 '14 at 08:02
  • No, this is not the strings file. This is the storyboard, as you requested. Perhaps you meant to ask how to automate making a label refer to a strings file, and to add comments to a .strings file? I don't think that's possible. – tooluser Jul 15 '14 at 20:59
  • the question is very clear, including the example. Have you had a look at it? `comment = "This is the comment to help translator"` – Mabedan Jul 16 '14 at 07:37
  • I think there was some miscommunication, I don't know what I said which made you upset. Anyway, I modified the question to be more clear about the `.strings` file. – Mabedan Jul 17 '14 at 08:16
  • Just saw this, thought it may be of interest for your situation: https://github.com/angelolloqui/AGi18n – tooluser Jul 23 '14 at 22:13
  • This should not be marked as the correct answer; @jjrscott's should be. Apple made the function of the Notes text field clearer in more recent versions of Xcode by adding the "Comment for Localizer" placeholder text. – NRitH Nov 08 '18 at 14:23
  • 1
    Indeed @NRitH it does seem like things changed four years later. Apple gets there! :joy: JastinBall, can you update it? – tooluser Sep 17 '21 at 16:15