I am using plists to store preset settings for my iOS app. I've created a default plist that I would like to copy and use as a template for all of my presets. However, when I duplicate the plist in Xcode, all of the types become strings! Any ideas why this happens or how to fix this?
As an example, my default.plist looks like this in Xcode
-mono boolean NO
-name string default
-portamento number 0.001
and after i duplicate it into a new file:
-mono string NO
-name string default
-portamento string 0.001
Thanks!!
//////Thanks Michael Dautermann for the answer to this. When I created the .plist file in Xcode, I had appended .plist manually. This resulted in a file that looked great in Xcode, but wasn't actually an .xml file. As a result, the datatypes were not included in the source code. So, simply create a .plist file (and don't append .plist) and all is well.
Related
Is there a XC command I can use to list all files for one target?
Unfortunately, I'm unaware of any environment variables available to a build script.
The best way that I know of would be to open the pbxproj file inside your xcodeproj bundle and parse it. Luckily, it seems to be in a plain text format compatible with plists. You could invoke the plutil command to convert it to XML or json for another tool/command to consume if that is your goal. You can utilize a "Run Script" build phase if you need this list as part of your build. You can also instantiate an NSDictionary directly with that file if that is useful to you.
The plist is pretty simple. It consists of a root dictionary with some version strings and a giant objects dictionary. Each object has an isa type and the one you are interested in is the PBXNativeTarget type. Scan until you find the target with the correct value for the name key. Once you find your target look at its buildPhases; AFICT the first entry in buildPhases is the key for the corresponding PBXSourcesBuildPhase object. That build phase object has a files array which contains yet another set of IDs (one for each file compiled into the target) which point to a PBXBuildFile object, which has a fileRef string as a key to another object, this time to a PBXFileReference. This object finally has a path key which will be the path to the source file.
Wait... did I say "simple"?
In my framework app, I have some localization files added and have a method to get
localised strings as follow
-(NSString *)getCurrentLocale{
return NSLocalizedString(#"mykey", nil);
}
and I have installed this pod into one demo app, and trying to get the locale but it always returns the key, (it returns 'mykey')
I have double checked the format and name (Localizable.strings) within the string files
all files has proper format
but I do have locale strings as values in my Localizable.strings
ex: "mykey" = "ar_SA";
any Idea where I am going wrong?
Usually, this happens when you don't have the Localizable.strings file in the appropriate language folder (e.g. de.lproj). Also, ensure you haven't put your Localizable.strings file in the Base.lproj folder, as the same problem will occur.
To summarize, make sure your project Localizations have their Localizable.strings files in their respective language folders to provide the correct translations.
Finally, if the above are true (and this may be obvious), the device must have its locale set to actually pull strings from a given language.
Reference: Internationalization and Localization Guide
Just to start, I really have no idea what Im doing. I was given this task for an internship, and am really learning as I go. I have multiple plist files, they consist of around 22 items each, and list values of colors. I need to merge all of these files into one, and am really not sure how to go about it. I have a certain structure I need to go by, and really Im not sure how to go about it. I was told to open the plists in texteditor and then paste all of the raw code into one text file, this doesn't seem to work as I only end up getting the values for the first plist I pasted into the text file. Any help would be nice. Thanks.
Assume your from.plist contains keys 1, 2 and to.plist contains 2, 3
Run this:
/usr/libexec/PlistBuddy -x -c "Merge from.plist" to.plist
to.plist will contain 1, 2, 3
There are a number of ways to handle this. By default a plist is a special form of XML file. If you figure out the syntax you can in fact use a text editor to merge the contents of multiple files together, but you need to make sure you get it right.
A plist file has a specific header for the entire file. You could not just copy/paste multiple plists together because then they would have that header repeated.
The next way to do it is programmatically. If you can figure out the type of outer collection these files contain (probably an array or a dictionary) then you could write a few lines of code that read in each of the plists as arrays, combines them using NSArray code (assuming they contain arrays of colors) and then save the combined array back to a new plist. As vadian says you can also use the NSPropertyListSerialization class. Thats a more general-pupose way of handling plist files, but it's also more complex and harder to figure out.
A third way to do it is in Xcode. If you right-click on a plist file and select "open in Xcode" it should give you Xcode's property list editor. You can then copy and paste the contents of the files together and save the results to a new file.
I figured it out!! First create the structure, or use the template given to you. I suggest opening this template/ structure in Xcode, as it makes it easier to switch between viewing the list as a plist and source code. Open your template as a source code. Then open each of your plists in text editor, and copy and paste the code from your plists into the appropriate area in your templates source code, then you can view it in Xcode as a property list to make sure it's correct. The only thing you have to be careful about here is making sure you are getting no errors. Otherwise this works great!!
I create tow Localizable.strings files one for english and the second for arabic :
/* The number 1 */
"LABEL_ONE" = "label number one";
I am using this code to get the string value:
[self.Lable1 setText:NSLocalizedString(#"LABEL_ONE", #"The number 1")];
but the app show "LABEL_ONE" instead of "label number one" ?
What's the problem ?
Thanks
Your string files name have to be Localizable.strings.
In addition to the top answer, the localization file has to be named Localizable.strings and not anything else.
Your code is correct, so the problem is elsewhere.
Here are some possibilities:
The Localized.strings file is not copied into the application bundle. To verify this focus on the Localized.strings file using the 'Project Navigator' and make sure your target is checked on the right pane under 'Target Membership'
There is some syntax issues within the Localized.strings file, i.e. missing ;
The code you quoted does not get executed. To verify put a breakpoint and see if it's reached or use some debug logs...
The string appears in the Localized.strings for Arabic but is missing for English.
Your problem is very simple:
The app doesn't find the file with translations.
So you must be sure that you create the localizable files with the correct name (for example en for english) and also that in your device (or simulator) you have set 1 of the languages prepared from you in these files.
Otherwise, the file is not found and is returned the key instead of the value.
try this answer it is work for me
I was having problems with this on the iOS Simulator. I ended up deleting the Localization.strings file in the simulator directory
( /Users/(me)/Library/Application Support/iPhone Simulator/5.0/Applications/(etc)/(project)/(application.app)
copied from here
https://stackoverflow.com/a/11657945
In my case cleaning the project after initially introducing i18n to it solved it.
Check whether you added any text/character by mistake after the ; in Localizable.strings file.
It doesn't show the error while running the app but XCode ignore all the key-value pair after this character, which leads to returning the key instead of values.
I put a + by mistake in string file and wasted 2 hours for this.
Make sure that the Target Membership is set to include your App and any other places you may need it. In my case, the membership was only set to the test folder
[Answer from August, 2017. Compiler may have changed]
Search for a syntax error in your .strings File
I had the following line:
"Changed your mind?" = "¿Cambiaste de opinión?";,
And somehow that made the compilation succeed, even the command plutil -lint Localizable.strings said it was okay. After I took the same comma down from each file in that line, now the compiler is able to detect there are errors.
The problem before was the compilation succeeded, but because of the comma the .strings file was actually wrong so nothing after the comma was read. I don't know if the comma has any use in .strings files.
Note:
plutil -lint Localizable.strings is used on the Terminal tu debug .strings files as Xcode cannot tell where the .strings compilation wen wrong.
I am attempting to use InAppSettingsKit to manage my settings. This uses the Settings.bundle with a .plist file and the .strings files for each of the languages being translated.
I can confirm that the translation of my strings is working properly outside of my application, using the Setting application. But when I am in my application, the translation is not occurring.
I think it comes down to code like this, from the InAppSettingsKit class IASKSettingsReader, with a couple logging statements that I thought my be helpful:
- (NSString*)titleForStringId:(NSString*)stringId {
NSLog(#"%#",[_bundle localizedStringForKey:stringId value:stringId table:self.localizationTable]);
NSLog(#"%#",[_bundle localizedInfoDictionary]);
return [_bundle localizedStringForKey:stringId value:stringId table:self.localizationTable];
}
If I understand correctly, this should be using a table with the name self.localizationTable as the source of the translation. This value is simply "Root". It's not a path to the Root.strings file in the selected language, so I am guessing that the method localizedStringForKey:value:table: must be using some global system reference that points to the correct path.
I have confirmed that the strings file name is "Root.strings" all around, with a capital R, including in the Root.plist file.
[_bundle localizedInfoDictionary] returns (null); It is doing this for two language settings of English and French.
I'm not sure how to debug this. Thanks for any help you can give.
I'm using InAppSettingsKit with localized text with no problems. Two things I can think of that you could check: are your Root.strings files located in the correct subdirectories of Settings.bundle (en.lproj and fr.lproj for English and French?
Is there a "Strings Filename" entry in your Root.plist? It should simply contain a string with value "Root"
It has been quite some time since I resolved this, and at the time, I didn't fully understand it. But, in the interest of closing out this question, I'll point to the following documentation for future reference:
NSBundle Class Reference
which refers to the following:
Resource Programming Guide
In the second document, refer to the section "String REsources -> Loading String Resources Into Your Code"
The solution contains a properly configured Root.strings file, which shows up in the file list like this: