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

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

Open
HKevin1993 opened this issue Nov 27, 2020 · 2 comments

Comments

@HKevin1993
Copy link

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

@HKevin1993 HKevin1993 added the bug Something isn't working label Nov 27, 2020
@nysander
Copy link

same here for:

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

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

@Jeehut
Copy link
Member

Jeehut commented Nov 13, 2021

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.

@Jeehut Jeehut added enhancement and removed bug Something isn't working labels Nov 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
@nysander @Jeehut @HKevin1993 and others