Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Table name #41

Closed
Disconnecter opened this issue Mar 24, 2015 · 10 comments
Closed

Table name #41

Disconnecter opened this issue Mar 24, 2015 · 10 comments

Comments

@Disconnecter
Copy link

Is this possible to past the table name from wich we import string key?

@nek023
Copy link
Owner

nek023 commented Mar 27, 2015

Do you mean completing the tableName parameter of NSLocalizedStringFromTable?
Maybe it's possible.
Please wait for the update.

@nek023
Copy link
Owner

nek023 commented Apr 1, 2015

I've updated Lin and now it can also complete the table name.
Please check in your environment.
If you're using Alcatraz, you will need to remove cache before re-installing, by running rm -rf ~/Library/Application\ Support/Alcatraz.

@Disconnecter
Copy link
Author

Y are my hero. Thnx

@Disconnecter
Copy link
Author

Can You explain how it works? Or give some instructions.
Because I want to add my own localization macros which look as.

#define LOCALIZE(STRING, TABLE) [[NSBundle mainBundle] localizedStringForKey:STRING value:UnlocalizedString table:TABLE]

Or if You can add it to repo, will be great

@Disconnecter Disconnecter reopened this Apr 1, 2015
@nek023
Copy link
Owner

nek023 commented Apr 1, 2015

OK.
You can find Completions.plist in Lin's source directory.

https://github.com/questbeat/Lin/blob/master/Lin/Completions.plist

It has regular expressions to find key and tableName parameter.
So if you want to add your own macro, you have to add a completion pattern to it.

@nek023
Copy link
Owner

nek023 commented Apr 1, 2015

  1. Open ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Lin.xcplugin/Contents/Resources/Completions.plist
  2. Add following <dict> to the root <array> element
  3. Restart the Xcode
    <dict>
        <key>LINFunctionName</key>
        <string>LOCALIZE</string>
        <key>LINTableNameCompletionPatterns</key>
        <array>
            <dict>
                <key>Objective-C</key>
                <string>LOCALIZE\s*\(\s*@&quot;(?:[^\\&quot;]|\\.)*&quot;\s*,\s*(@&quot;(?:[^\\&quot;]|\\.)*&quot;)</string>
                <key>Swift</key>
                <string></string>
            </dict>
            <dict>
                <key>Objective-C</key>
                <string>LOCALIZE\s*\(\s*@&quot;(?:[^\\&quot;]|\\.)*&quot;\s*,\s*(&lt;#TABLE#&gt;)</string>
                <key>Swift</key>
                <string></string>
            </dict>
        </array>
        <key>LINKeyCompletionPatterns</key>
        <array>
            <dict>
                <key>Objective-C</key>
                <string>LOCALIZE\s*\(\s*(\w*)</string>
                <key>Swift</key>
                <string></string>
            </dict>
            <dict>
                <key>Objective-C</key>
                <string>LOCALIZE\s*\(\s*(&lt;#STRING#&gt;)</string>
                <key>Swift</key>
                <string></string>
            </dict>
        </array>
    </dict>

@Disconnecter
Copy link
Author

Cool. Y are the best

@nico75005
Copy link

Does it work only for macros? Because I have a function in Swift (static func localizedString(key: String, comment: String) -> String) and I can't figure figure out if I doing it wrong or if it works only for macros

@nek023
Copy link
Owner

nek023 commented Aug 8, 2015

@nico75005
It should work with Swift functions because it just uses regular expression.
You have to modify Completion.plist if you want to use your own function.

@nico75005
Copy link

I tried to add this in the Completion.plist but it didn't work:

        <key>LINFunctionName</key>
        <string>LanguageHelper.localizedString</string>
        <key>LINTableNameCompletionPatterns</key>
        <array>
            <dict>
                <key>Swift</key>
                <string>LanguageHelper.localizedString\s*\(\s*&quot;(?:[^\\&quot;]|\\.)*&quot;\s*,\s*tableName\s*:\s*(&quot;(?:[^\\&quot;]|\\.)*&quot;)</string>
            </dict>
            <dict>
                <key>Swift</key>
                <string>LanguageHelper.localizedString\s*\(\s*&quot;(?:[^\\&quot;]|\\.)*&quot;\s*,\s*tableName\s*:\s*(&lt;#String\?#&gt;)</string>
            </dict>
        </array>
        <key>LINKeyCompletionPatterns</key>
        <array>
            <dict>
                <key>Objective-C</key>
                <string>LanguageHelper.localizedString\s*\(\s*(\w*)</string>
                <key>Swift</key>
                <string>LanguageHelper.localizedString\s*\(\s*(\w*)</string>
            </dict>
            <dict>
                <key>Objective-C</key>
                <string>LanguageHelper.localizedString\s*\(\s*(&lt;#key#&gt;)</string>
                <key>Swift</key>
                <string>LanguageHelper.localizedString\s*\(\s*(&lt;#key: String#&gt;)</string>
            </dict>
        </array>
    </dict>

I based it on the <dict> of NSLocalizedString and just changed the name of <string></string>
The fact that I'm only using 2 parameters (key and comment) instead of the four might be the reason?

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

No branches or pull requests

3 participants