konrad1977 / loco

A linter for Swift Localizations
MIT License
73 stars 2 forks source link

Compatibility with SwiftGen localized enums #4

Closed Thomas-ResG closed 1 year ago

Thomas-ResG commented 1 year ago

When using Loco on a project that has SwiftGen's generated enums, Loco shows warnings that the localized keys are unused.

Feature Request:

it would be great if Loco could also detect, in addition to NSLocalizedString, SwiftGen's L10n enum generated from the strings file.

https://github.com/SwiftGen/SwiftGen#strings

konrad1977 commented 1 year ago

Hi! Thanks for feedback. I'll look into this. But it might take some days/week(s).

Do you use Localizable.strings or Localizable.stringsdict? Loco doesn't support dicts (yet).

Is your code open sourced or is It a closed source project? Would be great to be able to run it directly with a test, I haven't used swiftgen my self.

Thomas-ResG commented 1 year ago

I am using Localizable.strings. The project I'm working on is closed source. From what I understand, SwiftGen takes in entries like this:

"test_Uppercase_underscore.lowerCaseFirstLetter.lowercasethroughout.TheFinalKeyword" = "some localization";

and generates enums in a file called Strings+Generated.swift like so:

internal enum L10n {
  internal enum TestUppercaseUnderscore {
    internal enum LowerCaseFirstLetter {
      internal enum Lowercasethroughout {
        /// this is a test localization
        internal static let theFinalKeyword = L10n.tr("Localizable", "test_Uppercase_underscore.lowerCaseFirstLetter.lowercasethroughout.TheFinalKeyword", fallback: "some localization")
      }
    }
  }
}
konrad1977 commented 1 year ago

Could you try the latest version I pushed to the master now. I added support for this (I think)

romaHerman commented 1 year ago

Hi @konrad1977 Thanks for the useful tools!

Any Chance to add support to a custom function call? e.g. I'm using a wrapper on top of NSLocalisedString so all my strings are being invoked through MyAppLocalisedString("key") and I'm receiving a lot of warnings now

Thomas-ResG commented 1 year ago

Hello, @konrad1977

I appreciate the update! however, the requirements and architecture of the project I'm working on has shifted, and we're no longer using swiftgen for translations, and unfortunately the branch with swiftgen translations has also been deleted so I can no longer test it. But thank you for your continued support for this repo! perhaps I will make use of it in a future project!

konrad1977 commented 1 year ago

@romaHerman Can you please create a separate issue for this, I know that is worked before I need to test it again. If you could paste some sample code how you want it to use would be great. Not a whole project just a sample so I can run som tests on it.

@Thomas-ResG I am using swiftgen in a project now so I can confirm that it works in one project at least.

konrad1977 commented 1 year ago

@romaHerman Fixed in the latest version of main. Please verify that it works.