class PrismicRails::LanguageService
The PrismicRails::LanguageService
tries to match your i18n locale to the Prismic locale.
E.g. If your rails app support the locales :en, :de and :fr and you want to support this locales with your prismic content you have to match this locals. In Prismic you have the possibility to define a finer graded set of locals, e.g. 'en-gb', 'en-us', 'de-de', 'de-ch' and so on. Unfortunately Prismic does not support a wildcard query on the locals, so we have solved this problem by setting up a matching logic.
You can define the matching logic in your PrismicRails
configureation.
Attributes
Stores the given locale
Public Class Methods
Calls the PrismicRails::LanguageService
with a i18n locale form rails. The PrismicRails::LanguageService
tries to match it into a prismic locale.
# File lib/prismic_rails/services/language_service.rb, line 24 def self.call(locale, reverse: false) if reverse new(locale).reverse() else new(locale).match() end end
Creates a instance of the class PrismicRails::LanguageService
# File lib/prismic_rails/services/language_service.rb, line 33 def initialize(locale) @locale = locale end
Public Instance Methods
Creates the language hash out of the PrismicRails::Config
# File lib/prismic_rails/services/language_service.rb, line 48 def language_hash HashWithIndifferentAccess.new(PrismicRails.config.languages) end
Tries to match the given locale to a prismic locale
# File lib/prismic_rails/services/language_service.rb, line 38 def match return language_hash[@locale.to_sym] || '*' end
Tries to reverse match the prismic locale to a rails locale
# File lib/prismic_rails/services/language_service.rb, line 43 def reverse return language_hash.key(@locale) end