Skip to content

Commit

Permalink
chore: Extracting available locales from CountryRepository.php
Browse files Browse the repository at this point in the history
  • Loading branch information
robinvdvleuten committed Nov 22, 2023
1 parent 65700f8 commit b6a293a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tasks/generate.rake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ namespace :addressing do
# As Ruby has no support for this hashing algorithm, we'll need to convert the hashes to SHA1.
normalize_subdivision_group_hash

puts "Extracting available locales from CountryRepository.php\n"
extract_available_locales

puts "Extracting definitions from AddressFormatRepository.php\n"
extract_address_definitions

Expand All @@ -53,6 +56,19 @@ def normalize_subdivision_group_hash
end
end

def extract_available_locales
country_repo = File.read("tmp/addressing/src/Country/CountryRepository.php")

# Extract locales from the $availableLocales variable.
locales_match = country_repo.match(/\$availableLocales = (\[[^\]]+\]);/m)
raise "Unable to extract available locales from CountryRepository.php" if locales_match.nil?

country_rb = File.read("lib/addressing/country.rb")
country_rb = country_rb.gsub(/@@available_locales = \[[^\]]+\]/m, "@@available_locales = #{locales_match[1].tr("'", '"')}")

File.write("lib/addressing/country.rb", country_rb)
end

def extract_address_definitions
address_format_repo = File.read("tmp/addressing/src/AddressFormat/AddressFormatRepository.php")

Expand Down

0 comments on commit b6a293a

Please sign in to comment.