Module: Jekyll::Filters
- Includes:
- Helpers
- Defined in:
- lib/jekyll/localization.rb
Instance Method Summary
collapse
Methods included from Helpers
#localize_posts, #localized_posts
Instance Method Details
#_localization_original_date_to_long_string ⇒ Object
348
|
# File 'lib/jekyll/localization.rb', line 348
alias_method :_localization_original_date_to_long_string, :date_to_long_string
|
#_localization_original_date_to_string ⇒ Object
341
|
# File 'lib/jekyll/localization.rb', line 341
alias_method :_localization_original_date_to_string, :date_to_string
|
#date_to_long_string(date, lang = lang) ⇒ Object
Overwrites the original method to generate localized date strings.
351
352
353
|
# File 'lib/jekyll/localization.rb', line 351
def date_to_long_string(date, lang = lang)
local_date_string(date, Localization::DATE_FMT_LONG[lang], lang)
end
|
#date_to_string(date, lang = lang) ⇒ Object
Overwrites the original method to generate localized date strings.
344
345
346
|
# File 'lib/jekyll/localization.rb', line 344
def date_to_string(date, lang = lang)
local_date_string(date, Localization::DATE_FMT_SHORT[lang], lang)
end
|
#human_lang(lang = lang) ⇒ Object
284
285
286
|
# File 'lib/jekyll/localization.rb', line 284
def human_lang(lang = lang)
translate(*Localization::HUMAN_LANGUAGES[lang]) || lang.capitalize
end
|
#lang ⇒ Object
272
273
274
275
276
277
278
|
# File 'lib/jekyll/localization.rb', line 272
def lang
if @context.respond_to?(:find_variable, true)
@context.send(:find_variable, 'page')['lang']
else
page.lang
end
end
|
#local_date_string(date, fmt, lang = lang) ⇒ Object
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
# File 'lib/jekyll/localization.rb', line 355
def local_date_string(date, fmt, lang = lang)
res = ''
fmt.scan(/%[EO]?(.)|(.)/) { |a, b|
res << case a
when nil then b
when 'A' then Localization::DAYNAMES[lang][date.wday]
when 'a' then Localization::ABBR_DAYNAMES[lang][date.wday]
when 'B' then Localization::MONTHNAMES[lang][date.month]
when 'b' then Localization::ABBR_MONTHNAMES[lang][date.month]
when 'c' then local_date_string(date, Localization::TIME_FMT[lang], lang)
when 'P' then Localization::MERIDIAN[lang][date.send(:hour) < 12 ? 0 : 1].downcase
when 'p' then Localization::MERIDIAN[lang][date.send(:hour) < 12 ? 0 : 1]
else '%' << a
end
} if fmt
date.strftime(res)
end
|
#local_posts ⇒ Object
298
299
300
|
# File 'lib/jekyll/localization.rb', line 298
def local_posts
localized_posts(@site.posts, @page)
end
|
#native_lang(lang = lang) ⇒ Object
288
289
290
|
# File 'lib/jekyll/localization.rb', line 288
def native_lang(lang = lang)
translate_lang(lang, *Localization::HUMAN_LANGUAGES[lang]) || lang.capitalize
end
|
#other_langs ⇒ Object
280
281
282
|
# File 'lib/jekyll/localization.rb', line 280
def other_langs
Localization::LANGUAGES - [lang]
end
|
#translate(*translations) ⇒ Object
Also known as:
t
call-seq:
t 'default', 'translation', ... => aString (Ruby-style with array)
'default' | t: 'translation', ... => aString (Liquid-style with array)
t 'en' => 'default', 'de' => 'translation', ... => aString (Ruby-style with hash)
{ 'en' => 'default', 'de' => 'translation', ... } | t => aString (Liquid-style with hash)
If array given, returns the argument whose position corresponds to the current language’s position in the Localization::LANGUAGES array. If that particular argument is missing, default is returned.
If hash given, returns the value for the current language. If that particular value is missing, the value for the default language is returned.
315
316
317
|
# File 'lib/jekyll/localization.rb', line 315
def translate(*translations)
translate_lang(lang, *translations)
end
|
#translate_lang(lang, *translations) ⇒ Object
Also known as:
tl
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
# File 'lib/jekyll/localization.rb', line 321
def translate_lang(lang, *translations)
translations.flatten!
if translations.last.is_a?(Hash)
hash = translations.pop
if translations.empty?
hash[key = lang] || hash[key.to_sym] ||
hash[key = Localization::LANGUAGES.first] || hash[key.to_sym]
else
raise ArgumentError, 'both hash and array given'
end
else
index = Localization::LANGUAGES.index(lang)
index && translations[index] || translations.first
end
end
|
#url_lang(url, lang = lang) ⇒ Object
292
293
294
295
296
|
# File 'lib/jekyll/localization.rb', line 292
def url_lang(url, lang = lang)
url = url.sub(Localization::LANG_END_RE, '')
url << '.' << lang if lang
url
end
|