0

I have a HTML string that needs to be localized; the only problem is that it has parameters, like this:

    NSString *htmlString = [NSString stringWithFormat:NSLocalizedString(@"<html><head>"
                        "<style type=\"text/css\"> body {font-family: \"Verdana\"; font-size: 12;} </style></head>"
                        "<body><h2>%@ %@</h2><p>email: %@<p>phone: %@<p>services: %@<p><img src=\"%@\"/>"  
                        "</body></html>",nil),
                        client.aClientFirstName,
                        client.aClientLastName,
                        client.aClientEMail,
                        client.aClientPrimaryPhone,
                        appt.aServices,
                        fileURL];

The problem is that the "key" never contains the same data, and therefore will never match. This works fine when working with 'en' (because it defaults to that when it can't find a match), but all other languages fail when it gets displayed in a UIPopover. The question is: is there a way to code around this so no matter what the 'client' info is, it will display properly for each localization?

1 Answer 1

1

In your Localizable.strings files, you should create a separate fixed key and put the html template as the value that contains the placeholder for the parameters, for example:

"HTML_STRING" = "<html><head><style type=\"text/css\"> body {font-family: \"Verdana\"; font-size: 12;} </style></head><body><h2>%@ %@</h2><p>email: %@<p>phone: %@<p>services: %@<p><img src=\"%@\"/></body></html>";

And then use the key in your code, for example:

NSString *htmlString = [NSString stringWithFormat:NSLocalizedString(@"HTML_STRING",nil),
                    client.aClientFirstName,
                    client.aClientLastName,
                    client.aClientEMail,
                    client.aClientPrimaryPhone,
                    appt.aServices,
                    fileURL];

Here your htmlString variable will give you the localized version of the string with parameters included.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much... works like a champ! That was the one thing I didn't think of...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.