Method: Translatomatic::ResourceFile::Base#locale_path

Defined in:
lib/translatomatic/resource_file/base.rb

#locale_path(locale) ⇒ Pathname

Create a path for the current resource file with a given locale

Parameters:

  • locale (String)

    The target locale

Returns:

  • (Pathname)

    The path of this resource file modified for the given locale



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/translatomatic/resource_file/base.rb', line 38

def locale_path(locale)
  basename = path.sub_ext('').basename.to_s

  extlist = extension_list
  if extlist.length >= 2 && loc_idx = find_locale(extlist)
    # extension(s) contains locale, replace it
    extlist[loc_idx] = locale.to_s
  elsif valid_locale?(basename)
    # basename is a locale name, replace it
    path.dirname + (locale.to_s + path.extname)
  else
    # remove any underscore and trailing text from basename
    deunderscored = basename.sub(/_.*?$/, '')
    # add _locale.ext
    filename = deunderscored + "_" + locale.to_s + path.extname
    path.dirname + filename
  end
end