Skip to content

Commit

Permalink
fix(street): fixing problem with street format locale in impostor tem…
Browse files Browse the repository at this point in the history
…plates
  • Loading branch information
lfenzo committed Apr 11, 2024
1 parent 8b5df7e commit c48132b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/data/localization/country/pt_BR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ pt_BR,CYM,KY,Ilhas Cayman,Ilhas Cayman
pt_BR,COD,CD,Congo,República Democrática do Congo
pt_BR,FRA,FR,França,República da França
pt_BR,MYS,MY,Malásia,Malásia
pt_BR,USA,US,Estados Unidos,Estados Unidos da América
6 changes: 3 additions & 3 deletions src/data/localization/street_format/en_US.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"surname street_suffix"
"firstname surname street_suffix"
"street_prefix street_suffix"
surname street_suffix
firstname surname street_suffix
street_prefix street_suffix
4 changes: 2 additions & 2 deletions src/data/localization/street_format/pt_BR.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"street_prefix firstname surname"
"street_prefix complete_name"
street_prefix firstname surname
street_prefix complete_name
52 changes: 48 additions & 4 deletions src/providers/localization.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""
render_localization_map(; src = nothing, dst = nothing, locale = nothing)
using Base: ocachefile_from_cachefile
"""
function render_localization_map(; src = nothing, dst = nothing, locale = nothing)

locales = _load!("localization", "locale", "noloc")
all_locales = convert.(String, unique(locales[:, :locale]))
all_locales = convert.(String, locales[:, :locale])

df = @chain begin
locales
Expand All @@ -16,6 +15,8 @@ function render_localization_map(; src = nothing, dst = nothing, locale = nothin
rightjoin(_load!("localization", "district", all_locales); on = "city")
end

df[:, :street] = street(convert.(String, df[:, :country_code]))

if !isnothing(locale)
df = filter(r -> r[:locale] in locale, df)
end
Expand Down Expand Up @@ -363,6 +364,8 @@ end

"""
street(n::Integer = 1; kws...)
street(options::Vector{<:AbstractString}, n::Integer; kws...)
street(mask::Vector{<:AbstractString}; kws...)
Generate `n` street names.
Expand All @@ -388,6 +391,47 @@ function street(n::Integer = 1; locale = session_locale())
return streets |> coerse_string_type
end

function street(options::Vector{<:AbstractString}, n::Integer; kws...)
streets = String[]

locales = _load!("localization", "locale", "noloc")
country_code_locale_map = Dict(
String(row[:country_code]) => String(row[:locale]) for row in eachrow(locales)
)

street_formats = Dict(
code => _load!("localization", "street_format", country_code_locale_map[code])
for code in unique(options)
)

for _ in 1:n
country_code = rand(keys(country_code_locale_map))
format = rand(street_formats[country_code][:, :street_format]) |> String
push!(streets, render_template(format; locale = country_code_locale_map[country_code]))
end

return streets |> coerse_string_type
end

function street(mask::Vector{<:AbstractString}; kws...)
streets = String[]

locales = _load!("localization", "locale", "noloc")
country_code_locale_map = Dict(
String(row[:country_code]) => String(row[:locale]) for row in eachrow(locales)
)

street_formats = Dict(
code => _load!("localization", "street_format", country_code_locale_map[code])
for code in unique(mask)
)

for country_code in mask
format = rand(street_formats[country_code][:, :street_format]) |> String
push!(streets, render_template(format; locale = country_code_locale_map[country_code]))
end
return streets |> coerse_string_type
end


"""
Expand Down Expand Up @@ -459,7 +503,7 @@ function address(n::Integer = 1; locale = session_locale())
return addresses |> coerse_string_type
end

function address(options::Vector{<:AbstractString}, n::Integer; level::Symbol = :state_cide, kws...)
function address(options::Vector{<:AbstractString}, n::Integer; level::Symbol = :state_code, kws...)
addresses = String[]

gb = @chain begin
Expand Down
1 change: 1 addition & 0 deletions src/providers/relation_restrictions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const LOCALIZATIONS::Dict{Symbol, Vector} = Dict(
:city,
:district,
:address,
:street,
],
)

Expand Down

0 comments on commit c48132b

Please sign in to comment.