Cocoapods is an open-source dependency management tool built with Ruby for the iOS and the Mac OS X platforms. It aims to make the developer’s life easier by downloading/updating/managing/configuring the libraries needed for your project for you. As developer, if you want to add your library to the Cocoapods’ repository, or if you want to manage your local libraries by Cocoapods, you need to create a description file which explains how to manage them. This description file is called a Podspec. There are a tons of tutorial which explains how to write a Podspec file, so I’ll not focus this blog post on this problematic (for more information you can visit this link).
In this article I’m going to show you a proper way to work with the localized string files with Cocoapods in order to avoid any possible collisions with another libraries’ string files.
During the development of the YLMoment library, some people rallied me problems using the YLMoment library and their own localized string files or with another libraries. The issues came from the fact that the YLMoment’s string file names and those of another shared the same name (here Localizable.strings) and by the way one of the localized string file was ignored.
To avoid this problem, a good practice is to bundled your strings files and use the library’s name as bundle name. In this way you will avoid the collision between the localized strings into your application. Here an example to show you how achieve this with Cocoapods and the Podspec file:
# If your library needs to work on both iOS and Mac OS X platforms,
# you'll need to specify two distinct bundle as following:
# iOS
s.ios.resource_bundle = { 'YLMoment-iOS' => ['YLMoment/Localization/*.lproj'] }
# Mac OS X
s.osx.resource_bundle = { 'YLMoment-OSX' => ['YLMoment/Localization/*.lproj'] }
How you able to generate different .strings files for different language?
Ok that was quite dumb of me. Got it.