Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8541963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:56:59+00:00 2026-06-11T11:56:59+00:00

I have a question regarding static libraries. I need to localize some text inside

  • 0

I have a question regarding static libraries. I need to localize some text inside my library. So I created a bundle where I put my different localized files. Then, I created a function like this :

NSString *MyLocalizedString(NSString* key, NSString* comment)
{
    static NSBundle* bundle = nil;
    if (!bundle)
    {
        NSString* path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"MyStaticLib.bundle"];
        bundle = [[NSBundle bundleWithPath:path] retain];
    }

    return [bundle localizedStringForKey:key value:@"" table:nil];
}

But when I use it, it always return the english localized string (besides my phone langage is French). I do not know why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:57:00+00:00Added an answer on June 11, 2026 at 11:57 am

    I’ve got the very same issue when doing the exactly same: I’ve a static library and a companion bundle file with image, localized string, etc..

    I’ve figured out that seems that the static can’t figure out the correct device localization (I’m sorry but I wasn’t able to find the reason of this issue) and I’ve fixed by doing this:

    @implementation NSBundle (KiosKitAdditions)
    
    + (NSBundle *)kioskitBundle
    {
        static NSBundle* kioskitBundle = nil;
        static dispatch_once_t predicate;
        dispatch_once(&predicate, ^{
    
            NSString *libraryBundlePath = [[NSBundle mainBundle] pathForResource:KKBundleName
                                                                          ofType:@"bundle"];
    
            NSBundle *libraryBundle = [[NSBundle bundleWithPath:libraryBundlePath] retain];
            NSString *langID        = [[NSLocale preferredLanguages] objectAtIndex:0];
            NSString *path          = [libraryBundle pathForResource:langID ofType:@"lproj"];
            kioskitBundle           = [[NSBundle bundleWithPath:path] retain];
        });
        return kioskitBundle;
    }
    
    @end
    

    As you can see I have created a category of NSBundle with a Class method that act very similar to [NSBundle mainBundle] and that return me the correct bundle for the static libray so I can use it everywhere I want, for example:

    #define KKLocalizedString(key) NSLocalizedStringFromTableInBundle(key, @"Localizable", [NSBundle kioskitBundle], @"")
    

    The code is very simple first I find the path for the static library bundle, find the current device language and then I create a new NSBundle whose path is library_path/device_language.lproj .

    A drawback of this approach is that you need to alway localize all of your asset and this can be a pain if you have a lot image in your bundle (but I think this is unlikely).

    If you don’t want to adopt my category approach you can change your code like this:

    NSString *MyLocalizedString(NSString* key, NSString* comment)
    {
        static NSBundle* bundle = nil;
        if (!bundle)
        {
            NSString *libraryBundlePath = [[NSBundle mainBundle] pathForResource:@"MyStaticLib"
                                                                          ofType:@"bundle"];
    
            NSBundle *libraryBundle = [NSBundle bundleWithPath:libraryBundlePath];
            NSString *langID        = [[NSLocale preferredLanguages] objectAtIndex:0];
            NSString *path          = [libraryBundle pathForResource:langID ofType:@"lproj"];
            bundle                  = [[NSBundle bundleWithPath:path] retain];
    
        }
    
        return [bundle localizedStringForKey:key value:@"" table:nil];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got some question regarding the shared and static libraries.So let me tell you
I have a question regarding static variables, or some other way to do so.
I have a question regarding static function in php. let's assume that I have
I have a question regarding the best practise of handling formated text when using
I've started working on some Android applications and have a question regarding how people
I have a question regarding static members and functions of non static classes. I
I have a question regarding loops within an email template. My current email library
I have a basic question regarding jQuery. I have a static time-selection box IE:
i have a question regarding operator overloading in cli/c++ environment static Length^ operator++(Length^ len)
Question regarding static variables in static classes. If i have a static class and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.