chriscatfr
chriscatfr

Reputation: 2662

Store localised string data on iPhone

Let's suppose that I want to store (and later update via internet) a simple database of words with their definition : - label - definition

According to you, what would be the best way to store them in different languages ?

there's a label and a definition in both French and English, and later we could add other languages.

EDIT: for the moment I can only think about a 3rd property : language

I would define the assessor to return the language according to the current settings, or english by default.

Coredata doesn't support the localization of data? it supports localization of property names

Upvotes: 1

Views: 230

Answers (2)

chewy
chewy

Reputation: 8267

assuming you have a large set of words, you can save them as an array (s)

as described here: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference.html#//apple_ref/doc/uid/20000172-CIAEAHFJ

example:

NSString *errString;
NSData *serialized =[NSPropertyListSerialization dataFromPropertyList:imgsData
                                               format:NSPropertyListBinaryFormat_v1_0
                                     errorDescription:&errString];

    [serialized writeToFile:dataFilePath atomically:YES];

    if (errString)
    {
        NSLog(@"%@" errString);
        [errString release]; // exception to the rules
    }

To read it back in, use

NSString *errString;
NSData *serialized = [NSData dataWithContentsOfFile:data
FilePath];



imgsData =
    [NSPropertyListSerialization propertyListFromData:serialized
                                     mutabilityOption:NSPropertyListMutableContainers
                                               format:NULL
                                     errorDescription:&errString];

if (errString)
{
    NSLog(@"%@" errString);
    [errString release]; // exception to the rules
}

Upvotes: 1

Praveen S
Praveen S

Reputation: 10393

You have to localise your text strings and support translations for the language you want to use. There are many tutorials on how this can be achieved. Its more like mapping enums to text. And text will be returned for the language you ask for. Here is a good start point for your requirement. Follow the steps there and you can modify them as per your needs once you get hold of localisation of strings.

Upvotes: 0

Related Questions