glebm/i18n-tasks

View on GitHub
lib/i18n/tasks/locale_pathname.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

module I18n::Tasks
  module LocalePathname
    class << self
      def replace_locale(path, from, to)
        path&.gsub(path_locale_re(from), to)
      end

      private

      def path_locale_re(locale)
        (@path_locale_res ||= {})[locale] ||= %r{(?<=^|[/.-])#{locale}(?=[/.])}
      end
    end
  end
end