This may seem like a stupid question. But I have a plist for different categories in a iPhone application.
categories.plist
<key>cat1</key>
<string>Players</string>
...
Is it possible to localize this strings? This categories are created in to Core Data when the app is started for the first time. And if the user changes language after first launch the category names will still be in the language as when the application was first launched.
Is it possible in some way to localize the strings in the plist?
You can easily localize the entire file. Just select the file in Xocde and click the + button in the Localization section of the File Inspector to add multiple languages. You can then translate the file for each language.
If you just want to translate the strings, I would put keys into the plist file and translate those keys via the normal Localizable.strings file. In your code, you would then not use the strings directly but translate them first with NSLocalizedString().
you would typically create a plist file for each localization (not individual keys).
since that would duplicate the categories in each localization and in many cases only the translations change (not necessarily other keys), you could work around this if you use a separate lookup table (plist) for the localized translations of the values in the category plist. then you would use the category plist keyed values as keys for another localized lookup table (which would need only strings).
Related
I should use different API keys for different schemes (like Debug, QA, Release).
And I want to use a custom .plist file for that (Config.plist). Not other ways because of my project's architecture.
I configured User-Defined Settings in Build Settings
I followed these steps:
Create a custom User-Defined Settings named MY_API_KEY,
Add API key to different schemes,
Create a new Config.plist's User-Defined Settings for read from Info.plist,
Write CONFIG_FILE to Info.plist,
Write MY_API_KEY to the custom plist (Config.plist),
So I want to read MyAPIKey value from Config.plist but it returns ${MY_API_KEY} as a String.
Expected result is "asdfsadf" (value from User-Defined Settings).
NOTE:
I didn't post my way for read values from plists because I'm using my custom services for read plists.
First of all, you should use parentheses instead of curly braces:
So change this:
${MY_API_KEY}
${CONFIG_FILE}
to this:
$(MY_API_KEY)
$(CONFIG_FILE)
And second of all, why you don't use different info.plist files for different environments?
You can use info.plist File attribute to assign different plist files for different environments:
So you can have entirely custom plist file per environment.
I have a project where I've setup localization using NSLocalizedString with keys instead of actual values for text parameters, i.e. something like this:
NSLocalizedString("RunningDistance", "distance for a marathon")
instead of this:
NSLocalizedString("Running distance.", "distance for a marathon")
Then, I exported them to xliff for translation and imported back; and it's all working.
Now, I want to add new strings (and lots of them).
I read that it is currently not recommended (and supported) to use genstrings for swift.
I thought I should export the development language to xliff, add translations and reimport. I tried this and I get the The XLIFF file does not contain a target language error.
Does this mean I need to add all those strings manually into Localizable.strings and elsewhere (as I'm using base localizations)?
Is there any other way to get this done, and import my base language xliff?
Let's say i have a xml file with a tag named which contains the number of fields i want to show in my tableView and in another xml file i have the information to be displayed in that tableView.
The question is : Should i create 2 different file in my project (xmlparse1.h and .m + xmlparse2.h and .m) or should i just put all my code in 1 (xmlparse.h + .m) and differenciate which file i am parsing at the moment with a bool or something like that in the code?
I am developing an iphone app on Xcode 4.3 mac os x 10.7.4 if this might change
EDIT: 1st file :
<MenuPrin>
<humidite>82,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</humidite>
<tempmoy>
189,124,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700
</tempmoy>
</MenuPrin>
2nd File :
<Instal>
<nbrField>2</nbrField>
</Instal>
So it looks like this. So, since nbrField is 2 I would take the 2 first value from tempMoy and humidite and show them in a tableView.
END OF EDIT
If how you're parsing is similar in both instances, to add two sets of files that do effectively the same thing would be extremely inefficient and considered bad practice. It makes a lot more sense to create a parser that can handle the two different files than to write two parsers that can only handle a specific file each.
To more specifically answer your question, I would determine which file you are parsing and behave accordingly, whether you do this with a bool or something else is up to you.
EDIT: Here is the idea that just popped into my head, so if for whatever reason this wont work for you(Like I said its been a while), or someone has a better idea, I'm all ears. You could still have a set of files(.h and .m) that contain the definition of your parser. Your parser could contain within it a two variables of type Object1 and Object2 which are built in such a way that they resemble the data structure that you need to store what you parse once for your first type of file, and a different definition for your second type of file. This way when parsing once you determine which file it is you are reading, it just changes which of these two objects you write into. There are also plenty of variations for how you could set this up, and I can also think of a few cases for what you might be trying to do where this might not work, but there is the idea regardless.
If you think that the two sets of files approach is better for the application you are trying to write and makes more sense to you, given what has been discussed in the comments, it isn't necessarily a bad idea.
In case if u want to create two table view in one view u need to create a single .h & .m file...If u want to create individual table view u need to create two .h & .m...
Try TBXML parser...that is the easiest way and less memory usage for xmlparsing...
is it possible to play movies out of a property list? Like is there's a "tag" with the filename in it which gets replaced by the actual iphone/ipad player? The movies are h.265 codec...
thanks
I'm assuming that you mean, can you use the property list as an array which will hold a bunch of filenames for movies that you want to play?
All the property list can be is a text file of sorts that contains a bunch of key-value pairs. I think you are misunderstanding what a property list file is.
Think about it this way: the info.plist file stores text data about your app when it runs or gets added to the AppStore. That's all it does though: stores text data. There are no special tricks like you're speaking of to get it to launch movies or anything else. You'd have to implement all of that in code yourself based on what the plist value was for a particular key.
In my application, I am using a plist. Please, can anyone explain what are the uses of plist with an example or a sample code?
In the context of iPhone development, Property Lists are a key-value store that your application can use to save and retrieve persistent data.
All iPhone applications have at least one of these by default, the Information Property List:
The information property list is a
file named Info.plist that is included
with every iPhone application project
created by Xcode. It is a property
list whose key-value pairs specify
essential runtime-configuration
information for the application. The
elements of the information property
list are organized in a hierarchy in
which each node is an entity such as
an array, dictionary, string, or other
scalar type.
Plist are XML files in a specific format. Prior to XML, they had a custom format now called 'old plist'. (You almost never see that anymore save in legacy code.)
Foundations collection classes automatically generate XML files in the plist format when you use their serialization methods to write them to disk. They also automatically read them back. You can also write your own serializers for your own custom objects. This allows you to persistently store complex objects in a robust, human readable format.
One use for plist for programmers is that it is easier to use the plist editor to input and manage a lot of data than it is to try and code it. For example, if you have an class that requires setting a large number of ivars, you can create a plist, read it into an NSArray or NSDictionary and then initialize the instance by passing it the dictionary.
I use this technique when I have to use a large number of paths to draw complex objects. You define the path in the plist file instead of the code and edit the path in the plist editor.
It's also a handy way to create a large amount of detailed test data.
PList means PropertyList
It is XML file format
It is mainly user for store and reterve the data
It can store the key-value pair
It's been a long time since I've looked at them, but plist is a short-form of "properties list" and can be used to store application configuration settings that need to persist between instances of an application's execution. Could be similar to a .properties file (I see those a lot on Java projects).
A plist is essentially just a data file, it stores information in a documented format.
From Wikipedia:
In the Mac OS X Cocoa, NeXTSTEP, and
GNUstep programming frameworks,
property list files are files that
store serialized objects. Property
list files use the filename extension
.plist, and thus are often referred to
as plist files. Property list files
are often used to store a user's
settings. They are also used to store
information about bundles and
applications, a task served by the
resource fork in the old Mac OS.
.plist
Info.plist is key/value persistence storage(property list) which is used by system and user. It contains user-friendly text in XML format. Info.plist is mandatory file for any Bundle. For example it contains Bundle id[About] which is usually is used by system but as a programmer/user you are not limited on changing/reading[More]. The same as you can add K/V for your own purposes and read it in runtime. You could noticed that some frameworks forces you to add K/V into your's application to identify you or some other cases.
.entitlements is a property list with enabled capabilities(e.g. ApplePay)
[Info.plist location]
[Vocabulary]