How does Monotouch manage resources (strings, images, etc.)? - iphone

In Android I put my application strings in a file called strings.xml. For example, for an Italian translation I need to create a values-it folder and put a strings.xml file with Italian labels inside this new folder.
How does Monotouch manage such internationalization of strings?

You would generally use Apple's localization features - special "lproj" folders in your app bundle containing localized versions of your nibs, files, string resources etc.
You can find more info in Apple's iOS Internationalization docs, and there are also some third-party tutorials that are useful.
Although MonoDevelop does not provide any explicit support for localization, simply adding the lproj folders to your project root and marking their contents as "Content" should add them into the app bundle properly.
Any resource you load from the bundle should then load the appropriate localized version, if present. This includes APIs that automatically load items from the bundle, such as instantiating views from xibs/nibs, and also APIs to explicit retrieve resources from the bundle. For example NSBundle.LocalizedString will load the appropriate string from your strings resources.

Related

how to bundle flutter desktop assets into a single file for production build

after building the flutter project for desktop, flutter copies all asset files inside the assets directory into the build/flutter_assets/assets which are easily accessible and modifiable (which is not secure at all!), user can change the whole images easily and do some kind of modding the app with no experience required! or even in the worst situation with modifying the AssetManifest he could change the runtime dynamic libs with the malicious libs and get a hook from the app.
most modern frameworks/languages have the option to embed the resources inside a single file (that makes it harder to modify the files / repack the resource file) for example C#(WPF/Win32) embeds the resources in the resource Resource section or even Electron (Javascript) embed the whole resources into a file (it's easy but better than nothing)
I didn't find any similar behavior in Flutter Desktop (Windows/Mac/Linux) is there any alternative for flutter?
For now [12/12/22] it seems flutter desktop won't use resources to bundle the resources into a single file.
So I've created two separate libraries to achieve this
https://github.com/kooroshh/bundler that compresses the whole given assets into a single file and encrypts it with AES-128
https://github.com/kooroshh/flutter_bundler that reads the bundle file from and decrypts it into the memory that can be used with Image.memory or Direct file access using Virtual Files.
I hope an official solution gets implemented in the flutter framework.

where in an XCode project does it set "InfoPlist.strings" as the filename to use for locationalization?

where in an XCode project does it set "InfoPlist.strings" as the filename to use for locationalization?
Just trying to understand how XCode pulls things together here. For example to set the app name specifically I can change this in "AppName_plist-Info.plist", however if I go localization it seems it then has to be set via the "InfoPlist.strings" files.
I can see in XCode where it specifies the "AppName_plist-Info.plist" file name, in the Target/BuildSettings/Packaging information area, but I don't see mention of "InfoPlist.strings", so how does Xcode/IOS know to override what is in "AppName_plist-Info.plist" based on what's in "InfoPlist.strings"?
Xcode doesn't really override the name, it creates localizations in your apps bundle. iOS will look for the name of the app in de localization folder to which the language of the system is set.
These files have pre-determent names, thus you can not set them.
All the localized files will be for example in bundle.app\en.lproj for english or bundle.app\nl.lprojfor dutch.

Load nib from file path

We might have a need for loading a nib using the results of
[NSBundle -pathForResource:ofType:inDirectory:forLocalization:]
I thought this would be possible, but all the methods I can find only want the name not leading path info.
We are exploring a way to provide both fr-Fr and fr-CA through one code base. Our client wants a fr-CA translation and we're afraid we might have another customer that wants a fr-Fr translation. I was thinking we could path to correct nib based on the selected language.
Thanks
The path lookup takes into account the user's locale preferences. If you provide the proper localization directories (.lproj), the right nib should be loaded by the system.
Per Apple's documentation:
The method first looks for a matching resource file in the non-localized resource directory of the specified bundle. (In Mac OS X, this directory is typically called Resources but in iOS, it is the main bundle directory.) If a matching resource file is not found, it then looks in the top level of any available language-specific “.lproj” directories. (The search order for the language-specific directories corresponds to the user’s preferences.) It does not recurse through other subdirectories at any of these locations. For more details see Internationalization Programming Topics.
Unfortunately, Apple's documentation is self-contradictory and incomplete. If you look at "Internationalization and Programming Topics", section "Language and Locale Designations", you will find under "Language and Locale IDs" this gem:
Important: In iOS, the bundle interfaces do not take dialect or script information into account when looking for localized resources; only the language designator code is considered. Therefore if your project includes language-specific project directories with both a language and region designator, those directories are ignored. The bundle interfaces in Mac OS X do support region designators in language-specific project directories.
This is not entirely true. If you look at Apple's own applications, you will see that iOS does support some region designations, but only the ones Apple cares about. See for example the list of .lproj directories in a recent Mobile Safari:
$ ls -d *.lproj
Dutch.lproj/ el.lproj/ pt_PT.lproj/
English.lproj/ en_GB.lproj/ ro.lproj/
French.lproj/ fi.lproj/ ru.lproj/
German.lproj/ he.lproj/ sk.lproj/
Italian.lproj/ hr.lproj/ sv.lproj/
Japanese.lproj/ hu.lproj/ th.lproj/
Spanish.lproj/ id.lproj/ tr.lproj/
ar.lproj/ ko.lproj/ uk.lproj/
ca.lproj/ no.lproj/ vi.lproj/
cs.lproj/ pl.lproj/ zh_CN.lproj/
da.lproj/ pt.lproj/ zh_TW.lproj/
Notice that two Chinese regions, a British English region, and a Portugal Portuguese region are supported. But none of these solves the problem of fr_CA versus fr_FR.
For that, let's look at MobileSafari again. It must implement its own smart lookup, because it has plenty of more finely distinguished StaticBookmarks-xx_YY.plist files.
So, that's the solution: Use the locale functions that are still available, and do your own lookup accordingly.
I don't understand the problem.
You can perfectly have two different NIBs, for France and Canada (french), as it's supported by Xcode.
Simply add new localization for your file(s):
Then use a view controller to load the NIB, with the initWithNibName method. The correct one will be used, depending on the device language settings.

iPhone support Multiple Languages

In my project, I need to support the Korean language. How is it possible - can anyone explain briefly with example, whether it is possible or not?
It's certainly possible.
You just tell Xcode to add a Korean localization to any of your application's localizable resources that need to change for that language. (Localizable resources include strings files, xib files, and potentially any images containing text.) Xcode will create a copy of your existing English resource, which you can modify and replace with a Korean-language equivalent.
Then when your application is run on a device with Korean set as its preferred language, iOS will automatically use the Korean resources intead of the English ones to present the application's user interface. If you have used good localization code practices (such as using NSLocalizedString to reference strings you present in the user interface) you shouldn't have to change any of your code to support different languages.
Check this guide on how to localize your apps for iPhone: http://www.icanlocalize.com/site/tutorials/iphone-applications-localization-guide/

how to creating localizable.strings file by code in iPhone

I am working on one multilanguage project which will download string from server depend on language selected by user. I would like to save this downloaded string into localizable.string file. So how could I do that? I know how genstrings works but I would like to generated *.strings file by code and save it. My code will read this *.strings file for localizable. Anybody know which api i have to use?
thanks in advance
Manu
Typically, localization depends on strings files that are within the app bundle. Since you can not modify the app bundle at run time, you will have to put the strings files you downlaod elsewhere and you will have to modify the usual localization methods to find and use those strings files.
Look at Apple's iPhone samples to see how they do localization and fetching of the strings, and see if you can replace all the local accesses of the localization resources with resources in another directory.