Localize-Swift icon indicating copy to clipboard operation
Localize-Swift copied to clipboard

How to use in Objective-C ?

Open aemgtz opened this issue 8 years ago • 4 comments

My project is mixing between swift and objective-c. I can't find the instruction to use with objective-c view controller.

aemgtz avatar Sep 28 '16 10:09 aemgtz

This might be a little bit late but for anyone facing the same problem, I have a simple solution, its shouldn't be permanent solution as this should be integrated by marmelroy.

The Solution:

In the file

Pods/Pods/Localize-Swift/Sources/Localize.swift

Insert the following class function

open class func getLocalizedString(_ wantedString: String) -> String {
        let localizedString = wantedString.localized()
        return localizedString
    }

Build the project again for the change to be implemented.

In your ViewController.h insert @import Localize_Swift;

In your ViewController.m, you can use [Localize getLocalizedString: @"String"]

Example:

To get the localized string for "First Name" you can use NSString *LocalizedFName = [Localize getLocalizedString: @"FName"];

MouMentos avatar Dec 28 '16 03:12 MouMentos

Hi @MouMentos, I like this solution.

We should make it (or something similar) a part of the framework. I didn't realise this was an issue many people faced. Improving usage from ObjC will be a goal for the next release.

marmelroy avatar Dec 28 '16 05:12 marmelroy

@MouMentos Thanks for your objective c localization solution.

sourabhsharmait avatar May 30 '17 09:05 sourabhsharmait

I get an error No known class method for selector 'getLocalizedString:'

MrVlad001 avatar Apr 16 '19 14:04 MrVlad001