Module: CFBundle::Localization
- Defined in:
- lib/cfbundle/localization.rb
Overview
Utility methods to perform localization.
Constant Summary collapse
- FILE_EXTENSION =
The file extension of localization directories.
'.lproj'.freeze
Class Method Summary collapse
-
.localizations_in(bundle) ⇒ Array
Returns all the localizations contained in a bundle.
-
.preferred_localizations(localizations, preferred_languages) ⇒ Array
Returns an ordered list of preferred localizations contained in a bundle.
Class Method Details
.localizations_in(bundle) ⇒ Array
Returns all the localizations contained in a bundle.
13 14 15 16 17 18 19 |
# File 'lib/cfbundle/localization.rb', line 13 def localizations_in(bundle) return [] unless bundle.storage.directory?(bundle.resources_directory) bundle.storage .foreach(bundle.resources_directory) .select { |path| File.extname(path) == FILE_EXTENSION } .map { |path| File.basename(path, FILE_EXTENSION) } end |
.preferred_localizations(localizations, preferred_languages) ⇒ Array
Returns an ordered list of preferred localizations contained in a bundle.
28 29 30 31 32 33 34 35 36 |
# File 'lib/cfbundle/localization.rb', line 28 def preferred_localizations(localizations, preferred_languages) preferred_languages.each do |language| result = matching_localizations(localizations, language) return result unless result.empty? result = alternate_regional_localizations(localizations, language) return result unless result.empty? end [] end |