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

Class Method Details

.localizations_in(bundle) ⇒ Array

Returns all the localizations contained in a bundle.

Parameters:

  • bundle (Bundle)

    The bundle to search.

Returns:

  • (Array)


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.

Parameters:

  • localizations (Array)

    An array of localization identifiers.

  • preferred_languages (Array)

    An array of strings (or symbols) corresponding to a user’s preferred languages.

Returns:

  • (Array)

See Also:



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