سؤال

I would like to get a legal doc based on the language that the user is currently using.

The code I have is this one:

     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *libraryDirectory = [paths objectAtIndex:0];
if (sender == privacyPolicyButton) {
        ppPath = [libraryDirectory stringByAppendingPathComponent:@"privacy_policy.html"];

    } else if (sender == termsOfServiceButton) {
        ppPath = [libraryDirectory stringByAppendingPathComponent:@"terms.html"];

    } else if (sender == endUserButton) {
        ppPath = [libraryDirectory stringByAppendingPathComponent:@"eula.html"];

    }

    NSData *ppData = nil;
    policyView.scrollView.scrollEnabled = NO;

    [loadingIndicator startAnimating];
    policyView.hidden = closePolicyButton.hidden = NO;
    privacyPolicyButton.hidden = termsOfServiceButton.hidden = endUserButton.hidden = YES;

    ppData = [NSData dataWithContentsOfFile:ppPath];
    NSLog(@"%@", ppPath);

    [policyView loadData:ppData MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:nil];

I have a version of each document in spanish and in english, how can I tell the path to use the version in spanish?

This is how the files look

هل كانت مفيدة؟

المحلول

The NSBundle class does this for you. Assuming your HTML files are part of the app's resource bundle, you can simply do:

NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"terms" ofType:@"html"];

This will give you the path to the proper terms.html file based on the user's locale/language setting.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top