- (NSString *)localizedStringForKey:(NSString *)key
value:(NSString *)value
table:(NSString *)tableName
Doc says about the tableName argument in the above method as: The receiver’s string table to search. If tableName is nil or is an empty string, the method attempts to use the table in Localizable.strings...
My question is if we create a Localizable.strings it creates a string file alone. No tables are created in our project. Where is the table actually? Is it possible to create such string tables manually? I have a need to do that in my project...
And my final question is - What value I have pass as the argument to the tableName parameter?
Thank you...
In that context, "table" refers to the file of translations. So for Localizable.strings, you can get translations from it with NSLocalizedStringFromTable(@"foo", @"Localizable", @"comment"). Localizable.strings is the default, however, so you'd typically just use NSLocalizedString(@"foo", @"comment"). If you add a new translation file (say, Settings.strings), then you'd have use the table name to refer to it.
By table - it just means a key-value pair.
There is more detail in the documentation
So yes - you have to create these manually - since you are using the NSBundle helper methods for localised strings - you can use - (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName
and then run genstrings
to generate the .strings file and the tables.
Edited to make this clearer The Strings table is just a list of key value pairs. If you generate a Localizable.strings file that contains this:
/* Text for saying hello */
"HelloText" = "Hello!";
Now you can copy this file to another localised .lproj file and change it to the values for the particular language:
"HelloText" = "Namaste!";
That's all they mean by a table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With