Module: Utopia::Middleware::Localization::Name

Defined in:
lib/utopia/middleware/localization/name.rb

Class Method Summary collapse

Class Method Details

.extract_locale(resource_name, all_locales) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/utopia/middleware/localization/name.rb', line 23

def self.extract_locale(resource_name, all_locales)
	resource_name = resource_name.split(".") unless resource_name.kind_of? Array

	# We either have a file extension or an existing locale
	if all_locales.include?(resource_name[-1])
		return resource_name[-1]
	elsif all_locales.include?(resource_name[-2])
		return resource_name[-2]
	end
	
	return nil
end

.localized(resource_name, locale, all_locales) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/utopia/middleware/localization/name.rb', line 36

def self.localized(resource_name, locale, all_locales)
	nonlocalized_name = nonlocalized(resource_name, all_locales)

	if locale == nil
		return nonlocalized_name
	end

	if nonlocalized_name.size == 1
		return nonlocalized_name.push(locale)
	else
		return nonlocalized_name.insert(-2, locale)
	end
end

.nonlocalized(resource_name, all_locales) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/utopia/middleware/localization/name.rb', line 10

def self.nonlocalized(resource_name, all_locales)
	resource_name = resource_name.split(".") unless resource_name.kind_of? Array

	# We either have a file extension or an existing locale
	if all_locales.include?(resource_name[-1])
		resource_name.delete_at(-1)
	elsif all_locales.include?(resource_name[-2])
		resource_name.delete_at(-2)
	end

	resource_name
end