Skip to content

Commit

Permalink
eh?
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Jul 3, 2024
1 parent 767f277 commit 4d87a25
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5,028 deletions.
50 changes: 37 additions & 13 deletions mix_tasks/update_english_translations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,36 @@ defmodule Mix.Tasks.UpdateEnglishTranslations do
subdivisions
|> Enum.map(fn %{"code" => code, "name" => debian_name} ->
short_code = code |> String.replace("-", "") |> String.downcase()
cldr_name = Map.get(cldr_translations, short_code)

if en_name = Map.get(cldr_translations, short_code) || manual_en_name(code, debian_name) do
{code, en_name}
cond do
cldr_name == debian_name ->
colored_put(
IO.ANSI.blue(),
"Debian and CLDR names are the same, assuming they are translated, check: #{debian_name}"
)

# don't add to translations json to keep it small
nil

cldr_name ->
colored_put(
IO.ANSI.green(),
"CLDR translation found for #{code}, please check: #{cldr_name}"
)

{code, cldr_name}

fallback_name = manual_en_name(code, debian_name) ->
{code, fallback_name}

true ->
colored_put(
IO.ANSI.yellow(),
"no translation found for #{code}, assuming Debian name is English, please check: #{debian_name}"
)

nil
end
end)
|> Enum.reject(&is_nil/1)
Expand Down Expand Up @@ -85,22 +112,15 @@ defmodule Mix.Tasks.UpdateEnglishTranslations do
end
end

defp manual_en_name(code, debian_name) do
IO.puts(
IO.ANSI.yellow() <>
"no translation override for #{code}, assuming Debian name is English, please check: #{debian_name}" <>
IO.ANSI.reset()
)

defp manual_en_name(_code, _debian_name) do
nil
end

defp warn_if_debian_got_english(code, manual_name, debian_name) do
if manual_name == debian_name do
IO.puts(
IO.ANSI.green() <>
"Debian seems to have localized #{code}, the manual translation can be removed" <>
IO.ANSI.reset()
colored_put(
IO.ANSI.green(),
"Debian seems to have localized #{code}, the manual translation can be removed"
)
end

Expand Down Expand Up @@ -178,4 +198,8 @@ defmodule Mix.Tasks.UpdateEnglishTranslations do
|> File.read!()
|> Jason.decode!()
end

defp colored_put(color, message) do
IO.puts(color <> message <> IO.ANSI.reset())
end
end
Loading

0 comments on commit 4d87a25

Please sign in to comment.