Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export for Localization generates unwanted translation units #252

Open
CosynPa opened this issue Aug 15, 2016 · 4 comments · Fixed by #766
Open

Export for Localization generates unwanted translation units #252

CosynPa opened this issue Aug 15, 2016 · 4 comments · Fixed by #766

Comments

@CosynPa
Copy link

CosynPa commented Aug 15, 2016

For example when I localize launchScreen.storyboard which has a label whose ID is "cZB-if-HYR", R.generated.swift will has the following code:

  /// This `R.string` struct is generated, and contains static references to 2 localization tables.
  struct string {
    /// This `R.string.launchScreen` struct is generated, and contains static references to 1 localization keys.
    struct launchScreen {
      /// zh-Hans translation: Label
      /// 
      /// Locales: zh-Hans
      static let cZBIfHYRText = StringResource(key: "cZB-if-HYR.text", tableName: "LaunchScreen", locales: ["zh-Hans"])

      /// zh-Hans translation: Label
      /// 
      /// Locales: zh-Hans
      static func cZBIfHYRText(_: Void) -> String {
        return NSLocalizedString("cZB-if-HYR.text", tableName: "LaunchScreen", comment: "")
      }

      private init() {}
    }

// ...

This line NSLocalizedString("cZB-if-HYR.text", tableName: "LaunchScreen", comment: "") will cause XCode "export for localization" to generate unwanted translation unit in the xliff file:

<trans-unit id="cZB-if-HYR.text">
        <source>cZB-if-HYR.text</source>
        <note>No comment provided by engineer.</note>
</trans-unit>

And the real translation unit for this label is already generated. And also the function cZBIfHYRText in R.genrated.swift is not human-readable, I think it should be removed.

@hefgi
Copy link

hefgi commented Dec 14, 2016

Any news on this issue ? Thanks

@mac-cain13
Copy link
Owner

@tomlokhorst would it be possible to cherry-pick that commit that fixed this?

@tomlokhorst
Copy link
Collaborator

This was never properly fixed.

The workaround of excluding files that are named after nibs works, but that might also exclude perfectly valid user-defined translations.

The correct solution would be:

  • Scan all storyboard and nibs
  • Find the id's for all localisable items (I assume these are all the views items under <subviews>, but there might be more)
  • Exclude these ids from being generated in R.string.*

I think this issue is purely cosmetic. The currently generated code is not needed, but isn't harmful either. Therefor we should go for the proper solution instead of a quick workaround that is potentially harmful.

@tomlokhorst
Copy link
Collaborator

I don't know why I closed this issue before, it wasn't fixed in 7.0.0.

What R.swift 7 did is collect all ids that look like generated ids, for storyboards and nibs. And then did nothing with them. So that didn't change anything.

This issue is fixed with #921, that finds the .strings files in *.lproj directories, that are siblings of a storyboard or nib (or intentdefinition), and then exclude those files from strings generation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants