FlineDev / BartyCrouch

Localization/I18n: Incrementally update/translate your Strings files from .swift, .h, .m(m), .storyboard or .xib files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Define a marco or function,meet a error:Argument is not a literal string

HKevin1993 opened this issue · comments

commented

Expected Behavior

no error

Actual Behavior

bartycrouch work,but throw a error with “bad entry in file /Users/xxx/Desktop/project_xxx/project_xxx/Macros.swift (line = 11): Argument is not a literal string.”

Steps to Reproduce the Problem

  1. define a function:
    func kkLocalizedString(_ key: String, comment: String) -> String {
    NSLocalizedString(key, tableName: "kkLocalizable", bundle: Bundle.main, value: "", comment: comment)
    }
  2. build project
  3. error

Specifications

  • Version: 4.3.1
  • Platform: iOS
  • IDE Version:Xcode 12.2

My point

bartycrouch script run before compile sources, then the "key" of NSLocalizedString is not string

same here for:

public extension String {
    func localized(_ parameters: CVarArg) -> Self {
        String(format: NSLocalizedString(self, comment: ""), parameters)
    }

    func localized() -> Self {
        NSLocalizedString(self, comment: "")
    }
}

BartyCrouch is (currently) using Apples ExtractLocStrings tool shipped as part of Xcode to detect Strings from code. So whatever limitations that tool has, the same limitations apply to BartyCrouch. Unfortunately, the approach you would like to take is not compatible with that tool, it only works with static strings.

I consider this an improvement, not a bug, so changing the tag. The expected behavior here was never documented to work.