Sha256: df84c36cd614474a4e6b3519cda5727bed61c6147554fdf804a20f8ed456e6eb

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

#	This file is part of the "Utopia Framework" project, and is released under the MIT license.
#	Copyright 2010 Samuel Williams. All rights reserved.
#	See <utopia.rb> for licensing details.

module Utopia
	module Middleware
		class Localization
			
			module Name
				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

				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

				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
			end
			
		end
	end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
utopia-0.10.0 lib/utopia/middleware/localization/name.rb
utopia-0.9.61 lib/utopia/middleware/localization/name.rb
utopia-0.9.60 lib/utopia/middleware/localization/name.rb
utopia-0.9.59 lib/utopia/middleware/localization/name.rb