mirror of
https://github.com/mirego/accent.git
synced 2024-09-11 10:55:28 +03:00
m1 stuff
This commit is contained in:
parent
4b142e7b23
commit
40d37a4526
@ -10,6 +10,7 @@ config :ueberauth, Ueberauth, providers: [{:dummy, {Accent.Auth.Ueberauth.DummyS
|
||||
|
||||
config :accent, Oban, crontab: false, queues: false, plugins: false
|
||||
|
||||
config :telemetry_ui, disabled: true
|
||||
config :goth, disabled: true
|
||||
config :tesla, logger_enabled: false, adapter: Tesla.Mock
|
||||
|
||||
|
@ -22,7 +22,7 @@ defmodule Accent.Document do
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@possible_formats Accent.DocumentFormat.slugs()
|
||||
@possible_formats Accent.DocumentFormat.ids()
|
||||
|
||||
def changeset(model, params) do
|
||||
model
|
||||
|
@ -1,55 +1,13 @@
|
||||
defmodule Accent.DocumentFormat do
|
||||
@enforce_keys ~w(name slug extension)a
|
||||
defstruct name: nil, slug: nil, extension: nil
|
||||
defmacro ids, do: Enum.map(Langue.modules(), & &1.id)
|
||||
|
||||
@type t :: struct
|
||||
|
||||
@all [
|
||||
%{name: "Simple JSON", slug: "simple_json", extension: "json"},
|
||||
%{name: "JSON", slug: "json", extension: "json"},
|
||||
%{name: "Apple .strings", slug: "strings", extension: "strings"},
|
||||
%{name: "Gettext", slug: "gettext", extension: "po"},
|
||||
%{name: "Rails YAML", slug: "rails_yml", extension: "yml"},
|
||||
%{name: "ES6 module", slug: "es6_module", extension: "js"},
|
||||
%{name: "Android XML", slug: "android_xml", extension: "xml"},
|
||||
%{name: "Java properties", slug: "java_properties", extension: "properties"},
|
||||
%{name: "Java properties XML", slug: "java_properties_xml", extension: "xml"},
|
||||
%{name: "CSV", slug: "csv", extension: "csv"},
|
||||
%{name: "Laravel PHP", slug: "laravel_php", extension: "php"},
|
||||
%{name: "Go I18n JSON", slug: "go_i18n_json", extension: "json"},
|
||||
%{name: "XLIFF 1.2", slug: "xliff_1_2", extension: "xlf"},
|
||||
%{name: "Resx 2.0", slug: "resx_2_0", extension: "resx"}
|
||||
]
|
||||
|
||||
@doc """
|
||||
Slugs used in document changeset validation
|
||||
|
||||
## Examples
|
||||
iex> Accent.DocumentFormat.slugs()
|
||||
["simple_json", "json", "strings", "gettext", "rails_yml", "es6_module", "android_xml", "java_properties", "java_properties_xml", "csv", "laravel_php", "go_i18n_json", "xliff_1_2", "resx_2_0"]
|
||||
"""
|
||||
defmacro slugs, do: Enum.map(@all, &Map.get(&1, :slug))
|
||||
|
||||
@doc """
|
||||
## Examples
|
||||
|
||||
iex> Accent.DocumentFormat.all()
|
||||
[
|
||||
%Accent.DocumentFormat{extension: "json", name: "Simple JSON", slug: "simple_json"},
|
||||
%Accent.DocumentFormat{extension: "json", name: "JSON", slug: "json"},
|
||||
%Accent.DocumentFormat{extension: "strings", name: "Apple .strings", slug: "strings"},
|
||||
%Accent.DocumentFormat{extension: "po", name: "Gettext", slug: "gettext"},
|
||||
%Accent.DocumentFormat{extension: "yml", name: "Rails YAML", slug: "rails_yml"},
|
||||
%Accent.DocumentFormat{extension: "js", name: "ES6 module", slug: "es6_module"},
|
||||
%Accent.DocumentFormat{extension: "xml", name: "Android XML", slug: "android_xml"},
|
||||
%Accent.DocumentFormat{extension: "properties", name: "Java properties", slug: "java_properties"},
|
||||
%Accent.DocumentFormat{extension: "xml", name: "Java properties XML", slug: "java_properties_xml"},
|
||||
%Accent.DocumentFormat{extension: "csv", name: "CSV", slug: "csv"},
|
||||
%Accent.DocumentFormat{extension: "php", name: "Laravel PHP", slug: "laravel_php"},
|
||||
%Accent.DocumentFormat{extension: "json", name: "Go I18n JSON", slug: "go_i18n_json"},
|
||||
%Accent.DocumentFormat{extension: "xlf", name: "XLIFF 1.2", slug: "xliff_1_2"},
|
||||
%Accent.DocumentFormat{extension: "resx", name: "Resx 2.0", slug: "resx_2_0"}
|
||||
]
|
||||
"""
|
||||
def all, do: Enum.map(@all, &struct(__MODULE__, &1))
|
||||
def all,
|
||||
do:
|
||||
Enum.map(Langue.modules(), fn module ->
|
||||
%{
|
||||
name: module.display_name(),
|
||||
slug: module.id(),
|
||||
extension: module.extension()
|
||||
}
|
||||
end)
|
||||
end
|
||||
|
@ -1,11 +1,10 @@
|
||||
defmodule Langue.Formatter.Android do
|
||||
@behaviour Langue.Formatter
|
||||
use Langue.Formatter,
|
||||
id: "android_xml",
|
||||
display_name: "Android XML",
|
||||
extension: "xml",
|
||||
parser: Langue.Formatter.Android.Parser,
|
||||
serializer: Langue.Formatter.Android.Serializer
|
||||
|
||||
alias Langue.Formatter.Android.{Parser, Serializer}
|
||||
|
||||
def name, do: "android_xml"
|
||||
def placeholder_regex, do: ~r/%(\d\$)?@/
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
end
|
||||
|
@ -1,11 +1,9 @@
|
||||
defmodule Langue.Formatter.CSV do
|
||||
@behaviour Langue.Formatter
|
||||
use Langue.Formatter,
|
||||
id: "csv",
|
||||
display_name: "CSV",
|
||||
extension: "csv",
|
||||
parser: Langue.Formatter.CSV.Parser,
|
||||
serializer: Langue.Formatter.CSV.Serializer
|
||||
|
||||
alias Langue.Formatter.CSV.{Parser, Serializer}
|
||||
|
||||
def name, do: "csv"
|
||||
def placeholder_regex, do: :not_supported
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
end
|
||||
|
@ -1,11 +1,10 @@
|
||||
defmodule Langue.Formatter.Es6Module do
|
||||
@behaviour Langue.Formatter
|
||||
use Langue.Formatter,
|
||||
id: "es6_module",
|
||||
display_name: "ES6 module",
|
||||
extension: "js",
|
||||
parser: Langue.Formatter.Es6Module.Parser,
|
||||
serializer: Langue.Formatter.Es6Module.Serializer
|
||||
|
||||
alias Langue.Formatter.Es6Module.{Parser, Serializer}
|
||||
|
||||
def name, do: "es6_module"
|
||||
def placeholder_regex, do: ~r/{{[^}]*}}/
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
end
|
||||
|
@ -1,11 +1,10 @@
|
||||
defmodule Langue.Formatter.Gettext do
|
||||
@behaviour Langue.Formatter
|
||||
use Langue.Formatter,
|
||||
id: "gettext",
|
||||
display_name: "Gettext",
|
||||
extension: "po",
|
||||
parser: Langue.Formatter.Gettext.Parser,
|
||||
serializer: Langue.Formatter.Gettext.Serializer
|
||||
|
||||
alias Langue.Formatter.Gettext.{Parser, Serializer}
|
||||
|
||||
def name, do: "gettext"
|
||||
def placeholder_regex, do: ~r/%{[^}]*}/
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
end
|
||||
|
@ -1,9 +1,10 @@
|
||||
defmodule Langue.Formatter.GoI18nJson do
|
||||
alias Langue.Formatter.GoI18nJson.{Parser, Serializer}
|
||||
use Langue.Formatter,
|
||||
id: "go_i18n_json",
|
||||
display_name: "Go I18n JSON",
|
||||
extension: "json",
|
||||
parser: Langue.Formatter.GoI18nJson.Parser,
|
||||
serializer: Langue.Formatter.GoI18nJson.Serializer
|
||||
|
||||
def name, do: "go_i18n_json"
|
||||
def placeholder_regex, do: ~r/{{\.[^}]*}}/
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
end
|
||||
|
@ -1,11 +1,10 @@
|
||||
defmodule Langue.Formatter.JavaProperties do
|
||||
@behaviour Langue.Formatter
|
||||
use Langue.Formatter,
|
||||
id: "java_properties",
|
||||
display_name: "Java properties",
|
||||
extension: "properties",
|
||||
parser: Langue.Formatter.JavaProperties.Parser,
|
||||
serializer: Langue.Formatter.JavaProperties.Serializer
|
||||
|
||||
alias Langue.Formatter.JavaProperties.{Parser, Serializer}
|
||||
|
||||
def name, do: "java_properties"
|
||||
def placeholder_regex, do: ~r/\${[^}]*}/
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
end
|
||||
|
@ -1,11 +1,10 @@
|
||||
defmodule Langue.Formatter.JavaPropertiesXml do
|
||||
@behaviour Langue.Formatter
|
||||
use Langue.Formatter,
|
||||
id: "java_properties_xml",
|
||||
display_name: "Java properties XML",
|
||||
extension: "xml",
|
||||
parser: Langue.Formatter.JavaPropertiesXml.Parser,
|
||||
serializer: Langue.Formatter.JavaPropertiesXml.Serializer
|
||||
|
||||
alias Langue.Formatter.JavaPropertiesXml.{Parser, Serializer}
|
||||
|
||||
def name, do: "java_properties_xml"
|
||||
def placeholder_regex, do: ~r/\${[^}]*}/
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
end
|
||||
|
@ -1,11 +1,10 @@
|
||||
defmodule Langue.Formatter.Json do
|
||||
@behaviour Langue.Formatter
|
||||
use Langue.Formatter,
|
||||
id: "json",
|
||||
display_name: "JSON",
|
||||
extension: "json",
|
||||
parser: Langue.Formatter.Json.Parser,
|
||||
serializer: Langue.Formatter.Json.Serializer
|
||||
|
||||
alias Langue.Formatter.Json.{Parser, Serializer}
|
||||
|
||||
def name, do: "json"
|
||||
def placeholder_regex, do: ~r/{{[^}]*}}/
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
end
|
||||
|
@ -1,11 +1,8 @@
|
||||
defmodule Langue.Formatter.LaravelPhp do
|
||||
@behaviour Langue.Formatter
|
||||
|
||||
alias Langue.Formatter.LaravelPhp.{Parser, Serializer}
|
||||
|
||||
def name, do: "laravel_php"
|
||||
def placeholder_regex, do: :not_supported
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
use Langue.Formatter,
|
||||
id: "laravel_php",
|
||||
display_name: "Laravel PHP",
|
||||
extension: "php",
|
||||
parser: Langue.Formatter.LaravelPhp.Parser,
|
||||
serializer: Langue.Formatter.LaravelPhp.Serializer
|
||||
end
|
||||
|
@ -1,18 +1,20 @@
|
||||
defmodule Langue.Formatter.Rails.Parser do
|
||||
@behaviour Langue.Formatter.Parser
|
||||
if Langue.Formatter.Rails.enabled?() do
|
||||
defmodule Langue.Formatter.Rails.Parser do
|
||||
@behaviour Langue.Formatter.Parser
|
||||
|
||||
alias Langue.Utils.{NestedParserHelper, Placeholders}
|
||||
alias Langue.Utils.{NestedParserHelper, Placeholders}
|
||||
|
||||
def parse(%{render: render}) do
|
||||
{:ok, [content]} = :fast_yaml.decode(render)
|
||||
def parse(%{render: render}) do
|
||||
{:ok, [content]} = :fast_yaml.decode(render)
|
||||
|
||||
entries =
|
||||
content
|
||||
|> hd()
|
||||
|> elem(1)
|
||||
|> NestedParserHelper.parse()
|
||||
|> Placeholders.parse(Langue.Formatter.Rails.placeholder_regex())
|
||||
entries =
|
||||
content
|
||||
|> hd()
|
||||
|> elem(1)
|
||||
|> NestedParserHelper.parse()
|
||||
|> Placeholders.parse(Langue.Formatter.Rails.placeholder_regex())
|
||||
|
||||
%Langue.Formatter.ParserResult{entries: entries}
|
||||
%Langue.Formatter.ParserResult{entries: entries}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,11 +1,9 @@
|
||||
defmodule Langue.Formatter.Rails do
|
||||
@behaviour Langue.Formatter
|
||||
use Langue.Formatter,
|
||||
id: "rails_yml",
|
||||
display_name: "Rails YAML",
|
||||
extension: "yml"
|
||||
|
||||
alias Langue.Formatter.Rails.{Parser, Serializer}
|
||||
|
||||
def name, do: "rails_yml"
|
||||
def enabled?, do: Code.ensure_loaded?(:fast_yaml)
|
||||
def placeholder_regex, do: ~r/%{[^}]*}/
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
end
|
||||
|
@ -1,20 +1,22 @@
|
||||
defmodule Langue.Formatter.Rails.Serializer do
|
||||
@behaviour Langue.Formatter.Serializer
|
||||
if Langue.Formatter.Rails.enabled?() do
|
||||
defmodule Langue.Formatter.Rails.Serializer do
|
||||
@behaviour Langue.Formatter.Serializer
|
||||
|
||||
alias Langue.Utils.NestedSerializerHelper
|
||||
alias Langue.Utils.NestedSerializerHelper
|
||||
|
||||
@white_space_regex ~r/(:|-) \n/
|
||||
@white_space_regex ~r/(:|-) \n/
|
||||
|
||||
def serialize(%{entries: entries, language: language}) do
|
||||
render =
|
||||
%{language.slug => entries}
|
||||
|> Enum.with_index(-1)
|
||||
|> Enum.map(&NestedSerializerHelper.map_value(elem(&1, 0), elem(&1, 1)))
|
||||
|> :fast_yaml.encode()
|
||||
|> IO.chardata_to_string()
|
||||
|> String.replace(@white_space_regex, "\\1\n")
|
||||
|> Kernel.<>("\n")
|
||||
def serialize(%{entries: entries, language: language}) do
|
||||
render =
|
||||
%{language.slug => entries}
|
||||
|> Enum.with_index(-1)
|
||||
|> Enum.map(&NestedSerializerHelper.map_value(elem(&1, 0), elem(&1, 1)))
|
||||
|> :fast_yaml.encode()
|
||||
|> IO.chardata_to_string()
|
||||
|> String.replace(@white_space_regex, "\\1\n")
|
||||
|> Kernel.<>("\n")
|
||||
|
||||
%Langue.Formatter.SerializerResult{render: render}
|
||||
%Langue.Formatter.SerializerResult{render: render}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,11 +1,8 @@
|
||||
defmodule Langue.Formatter.Resx20 do
|
||||
@behaviour Langue.Formatter
|
||||
|
||||
alias Langue.Formatter.Resx20.{Parser, Serializer}
|
||||
|
||||
def name, do: "resx_2_0"
|
||||
def placeholder_regex, do: :not_supported
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
use Langue.Formatter,
|
||||
id: "resx_2_0",
|
||||
display_name: "Resx 2.0",
|
||||
extension: "resx",
|
||||
parser: Langue.Formatter.Resx20.Parser,
|
||||
serializer: Langue.Formatter.Resx20.Serializer
|
||||
end
|
||||
|
@ -1,11 +1,10 @@
|
||||
defmodule Langue.Formatter.SimpleJson do
|
||||
@behaviour Langue.Formatter
|
||||
use Langue.Formatter,
|
||||
id: "simple_json",
|
||||
display_name: "Simple JSON",
|
||||
extension: "json",
|
||||
parser: Langue.Formatter.SimpleJson.Parser,
|
||||
serializer: Langue.Formatter.SimpleJson.Serializer
|
||||
|
||||
alias Langue.Formatter.SimpleJson.{Parser, Serializer}
|
||||
|
||||
def name, do: "simple_json"
|
||||
def placeholder_regex, do: ~r/{{[^}]*}}/
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
end
|
||||
|
@ -1,11 +1,10 @@
|
||||
defmodule Langue.Formatter.Strings do
|
||||
@behaviour Langue.Formatter
|
||||
use Langue.Formatter,
|
||||
id: "strings",
|
||||
display_name: "Apple .strings",
|
||||
extension: "strings",
|
||||
parser: Langue.Formatter.Strings.Parser,
|
||||
serializer: Langue.Formatter.Strings.Serializer
|
||||
|
||||
alias Langue.Formatter.Strings.{Parser, Serializer}
|
||||
|
||||
def name, do: "strings"
|
||||
def placeholder_regex, do: ~r/%(\d\$)?s/
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
end
|
||||
|
@ -1,11 +1,8 @@
|
||||
defmodule Langue.Formatter.XLIFF12 do
|
||||
@behaviour Langue.Formatter
|
||||
|
||||
alias Langue.Formatter.XLIFF12.{Parser, Serializer}
|
||||
|
||||
def name, do: "xliff_1_2"
|
||||
def placeholder_regex, do: :not_supported
|
||||
|
||||
defdelegate parse(map), to: Parser
|
||||
defdelegate serialize(map), to: Serializer
|
||||
use Langue.Formatter,
|
||||
id: "xliff_1_2",
|
||||
display_name: "XLIFF 1.2",
|
||||
extension: "xlf",
|
||||
parser: Langue.Formatter.XLIFF12.Parser,
|
||||
serializer: Langue.Formatter.XLIFF12.Serializer
|
||||
end
|
||||
|
@ -1,29 +1,32 @@
|
||||
defmodule Langue do
|
||||
@format_modules [
|
||||
Langue.Formatter.Android,
|
||||
Langue.Formatter.CSV,
|
||||
Langue.Formatter.Es6Module,
|
||||
Langue.Formatter.Gettext,
|
||||
Langue.Formatter.JavaProperties,
|
||||
Langue.Formatter.JavaPropertiesXml,
|
||||
Langue.Formatter.Json,
|
||||
Langue.Formatter.Rails,
|
||||
Langue.Formatter.SimpleJson,
|
||||
Langue.Formatter.Strings,
|
||||
Langue.Formatter.LaravelPhp,
|
||||
Langue.Formatter.GoI18nJson,
|
||||
Langue.Formatter.XLIFF12,
|
||||
Langue.Formatter.Resx20
|
||||
]
|
||||
Langue.Formatter.Android,
|
||||
Langue.Formatter.CSV,
|
||||
Langue.Formatter.Es6Module,
|
||||
Langue.Formatter.Gettext,
|
||||
Langue.Formatter.JavaProperties,
|
||||
Langue.Formatter.JavaPropertiesXml,
|
||||
Langue.Formatter.Json,
|
||||
Langue.Formatter.Rails,
|
||||
Langue.Formatter.SimpleJson,
|
||||
Langue.Formatter.Strings,
|
||||
Langue.Formatter.LaravelPhp,
|
||||
Langue.Formatter.GoI18nJson,
|
||||
Langue.Formatter.XLIFF12,
|
||||
Langue.Formatter.Resx20
|
||||
]
|
||||
|> Enum.filter(& &1.enabled?())
|
||||
|
||||
for module <- @format_modules, name = module.name() do
|
||||
def parser_from_format(unquote(name)), do: {:ok, &unquote(module).parse(&1)}
|
||||
def modules, do: @format_modules
|
||||
|
||||
for module <- @format_modules, id = module.id() do
|
||||
def parser_from_format(unquote(id)), do: {:ok, &unquote(module).parse(&1)}
|
||||
end
|
||||
|
||||
def parser_from_format(_), do: {:error, :unknown_parser}
|
||||
|
||||
for module <- @format_modules, name = module.name() do
|
||||
def serializer_from_format(unquote(name)), do: {:ok, &unquote(module).serialize(&1)}
|
||||
for module <- @format_modules, id = module.id() do
|
||||
def serializer_from_format(unquote(id)), do: {:ok, &unquote(module).serialize(&1)}
|
||||
end
|
||||
|
||||
def serializer_from_format(_), do: {:error, :unknown_serializer}
|
||||
|
@ -2,8 +2,37 @@ defmodule Langue.Formatter do
|
||||
alias Langue.Formatter.ParserResult
|
||||
alias Langue.Formatter.SerializerResult
|
||||
|
||||
@callback name() :: String.t()
|
||||
@callback enabled?() :: boolean()
|
||||
@callback id() :: String.t()
|
||||
@callback display_name() :: String.t()
|
||||
@callback extension() :: String.t()
|
||||
@callback placeholder_regex() :: Regex.t() | :not_supported
|
||||
@callback parse(SerializerResult.t()) :: Langue.Formatter.Parser.result()
|
||||
@callback serialize(ParserResult.t()) :: Langue.Formatter.Serializer.result()
|
||||
|
||||
defmacro __using__(opts) do
|
||||
quote do
|
||||
@behaviour Langue.Formatter
|
||||
|
||||
def id, do: unquote(opts[:id])
|
||||
def display_name, do: unquote(opts[:display_name])
|
||||
def extension, do: unquote(opts[:extension])
|
||||
def placeholder_regex, do: :not_supported
|
||||
def enabled?, do: true
|
||||
|
||||
if Keyword.has_key?(unquote(opts), :parser) do
|
||||
defdelegate parse(map), to: unquote(opts[:parser])
|
||||
else
|
||||
def parse(_), do: nil
|
||||
end
|
||||
|
||||
if Keyword.has_key?(unquote(opts), :serializer) do
|
||||
defdelegate serialize(map), to: unquote(opts[:serializer])
|
||||
else
|
||||
def serialize(_), do: nil
|
||||
end
|
||||
|
||||
defoverridable placeholder_regex: 0, enabled?: 0, parse: 1, serialize: 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -16,7 +16,6 @@ defmodule Langue.Utils.LineByLineHelper.Parser do
|
||||
acc
|
||||
|> Map.put(:line, line)
|
||||
|> Map.put(:captures, Regex.named_captures(prop_line_regex, line))
|
||||
|> IO.inspect
|
||||
|> build_entry()
|
||||
|> add_entries()
|
||||
end
|
||||
|
18
mix.exs
18
mix.exs
@ -66,7 +66,6 @@ defmodule Accent.Mixfile do
|
||||
|
||||
# Utils
|
||||
{:p1_utils, "1.0.15", override: true},
|
||||
{:fast_yaml, github: "processone/fast_yaml", ref: "e789f68895f71b7ad31057177810ca0161bf790e"},
|
||||
{:jsone, "~> 1.4"},
|
||||
{:mochiweb, "~> 2.18"},
|
||||
{:httpoison, "~> 1.1"},
|
||||
@ -119,7 +118,22 @@ defmodule Accent.Mixfile do
|
||||
{:credo_envvar, "~> 0.1.0", only: ~w(dev test)a, runtime: false},
|
||||
{:excoveralls, "~> 0.8", only: :test},
|
||||
{:phoenix_live_reload, "~> 1.0", only: :dev}
|
||||
]
|
||||
] ++
|
||||
system_specific_deps()
|
||||
end
|
||||
|
||||
defp system_specific_deps do
|
||||
is_apple_arm64 =
|
||||
:os.type() === {:unix, :darwin} and
|
||||
not List.starts_with?(:erlang.system_info(:system_architecture), ~c"x86_64")
|
||||
|
||||
if is_apple_arm64 do
|
||||
[]
|
||||
else
|
||||
[
|
||||
{:fast_yaml, github: "processone/fast_yaml", ref: "e789f68895f71b7ad31057177810ca0161bf790e"}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
defp aliases do
|
||||
|
@ -1,5 +1,5 @@
|
||||
defmodule AccentTest.Hook do
|
||||
use Accent.RepoCase, async: false
|
||||
use Accent.RepoCase, async: true
|
||||
use Oban.Testing, repo: Accent.Repo
|
||||
|
||||
alias Accent.{
|
||||
|
@ -1,27 +1,29 @@
|
||||
defmodule LangueTest.Formatter.Rails do
|
||||
use ExUnit.Case, async: true
|
||||
if Langue.Formatter.Rails.enabled?() do
|
||||
defmodule LangueTest.Formatter.Rails do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
Code.require_file("expectation_test.exs", __DIR__)
|
||||
Code.require_file("expectation_test.exs", __DIR__)
|
||||
|
||||
alias Langue.Formatter.Rails
|
||||
alias Langue.Formatter.Rails
|
||||
|
||||
@tests [
|
||||
EmptyValue,
|
||||
NestedValues,
|
||||
ArrayValues,
|
||||
PluralValues,
|
||||
IntegerValues,
|
||||
PlaceholderValues,
|
||||
UnicodeValues
|
||||
]
|
||||
@tests [
|
||||
EmptyValue,
|
||||
NestedValues,
|
||||
ArrayValues,
|
||||
PluralValues,
|
||||
IntegerValues,
|
||||
PlaceholderValues,
|
||||
UnicodeValues
|
||||
]
|
||||
|
||||
for test <- @tests, module = Module.concat(LangueTest.Formatter.Rails.Expectation, test) do
|
||||
test "rails #{test}" do
|
||||
{expected_parse, result_parse} = Accent.FormatterTestHelper.test_parse(unquote(module), Rails)
|
||||
{expected_serialize, result_serialize} = Accent.FormatterTestHelper.test_serialize(unquote(module), Rails)
|
||||
for test <- @tests, module = Module.concat(LangueTest.Formatter.Rails.Expectation, test) do
|
||||
test "rails #{test}" do
|
||||
{expected_parse, result_parse} = Accent.FormatterTestHelper.test_parse(unquote(module), Rails)
|
||||
{expected_serialize, result_serialize} = Accent.FormatterTestHelper.test_serialize(unquote(module), Rails)
|
||||
|
||||
assert expected_parse == result_parse
|
||||
assert expected_serialize == result_serialize
|
||||
assert expected_parse == result_parse
|
||||
assert expected_serialize == result_serialize
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -93,34 +93,36 @@ defmodule AccentTest.TranslationsRenderer do
|
||||
assert render == ""
|
||||
end
|
||||
|
||||
test "render rails with locale", %{project: project, revision: revision} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "my-test", format: "rails_yml"})
|
||||
if Langue.Formatter.Rails.enabled?() do
|
||||
test "render rails with locale", %{project: project, revision: revision} do
|
||||
document = Repo.insert!(%Document{project_id: project.id, path: "my-test", format: "rails_yml"})
|
||||
|
||||
translation =
|
||||
%Translation{
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
corrected_text: "A",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
}
|
||||
|> Repo.insert!()
|
||||
translation =
|
||||
%Translation{
|
||||
key: "a",
|
||||
proposed_text: "A",
|
||||
corrected_text: "A",
|
||||
revision_id: revision.id,
|
||||
document_id: document.id
|
||||
}
|
||||
|> Repo.insert!()
|
||||
|
||||
%{render: render} =
|
||||
TranslationsRenderer.render_translations(%{
|
||||
master_translations: [],
|
||||
master_language: revision.language,
|
||||
translations: [translation],
|
||||
document: document,
|
||||
language: %Language{slug: "fr"}
|
||||
})
|
||||
%{render: render} =
|
||||
TranslationsRenderer.render_translations(%{
|
||||
master_translations: [],
|
||||
master_language: revision.language,
|
||||
translations: [translation],
|
||||
document: document,
|
||||
language: %Language{slug: "fr"}
|
||||
})
|
||||
|
||||
expected_render = """
|
||||
"fr":
|
||||
"a": "A"
|
||||
"""
|
||||
expected_render = """
|
||||
"fr":
|
||||
"a": "A"
|
||||
"""
|
||||
|
||||
assert render == expected_render
|
||||
assert render == expected_render
|
||||
end
|
||||
end
|
||||
|
||||
test "render xliff and revision overrides on source revision", %{project: project, revision: revision} do
|
||||
|
@ -170,19 +170,21 @@ defmodule AccentTest.ExportController do
|
||||
"""
|
||||
end
|
||||
|
||||
test "export with language overrides", %{conn: conn, project: project, revision: revision} do
|
||||
revision = Repo.update!(Ecto.Changeset.change(revision, %{slug: "testtest"}))
|
||||
document = %Document{project_id: project.id, path: "test2", format: "rails_yml"} |> Repo.insert!()
|
||||
%Translation{revision_id: revision.id, key: "ok", corrected_text: "bar", proposed_text: "bar", document_id: document.id, file_index: 2} |> Repo.insert!()
|
||||
%Translation{revision_id: revision.id, key: "test", corrected_text: "foo", proposed_text: "foo", document_id: document.id, file_index: 1} |> Repo.insert!()
|
||||
if Langue.Formatter.Rails.enabled?() do
|
||||
test "export with language overrides", %{conn: conn, project: project, revision: revision} do
|
||||
revision = Repo.update!(Ecto.Changeset.change(revision, %{slug: "testtest"}))
|
||||
document = %Document{project_id: project.id, path: "test2", format: "rails_yml"} |> Repo.insert!()
|
||||
%Translation{revision_id: revision.id, key: "ok", corrected_text: "bar", proposed_text: "bar", document_id: document.id, file_index: 2} |> Repo.insert!()
|
||||
%Translation{revision_id: revision.id, key: "test", corrected_text: "foo", proposed_text: "foo", document_id: document.id, file_index: 1} |> Repo.insert!()
|
||||
|
||||
params = %{order_by: "", project_id: project.id, language: revision.slug, document_format: document.format, document_path: document.path}
|
||||
response = get(conn, export_path(conn, [], params))
|
||||
params = %{order_by: "", project_id: project.id, language: revision.slug, document_format: document.format, document_path: document.path}
|
||||
response = get(conn, export_path(conn, [], params))
|
||||
|
||||
assert response.resp_body == """
|
||||
"testtest":
|
||||
"test": "foo"
|
||||
"ok": "bar"
|
||||
"""
|
||||
assert response.resp_body == """
|
||||
"testtest":
|
||||
"test": "foo"
|
||||
"ok": "bar"
|
||||
"""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -92,22 +92,24 @@ defmodule AccentTest.ExportJIPTController do
|
||||
assert response.status == 404
|
||||
end
|
||||
|
||||
test "export with language overrides", %{conn: conn, project: project, revision: revision, language: language} do
|
||||
revision = Repo.update!(Ecto.Changeset.change(revision, %{slug: "testtest"}))
|
||||
document = %Document{project_id: project.id, path: "test2", format: "rails_yml"} |> Repo.insert!()
|
||||
%Translation{revision_id: revision.id, key: "ok", corrected_text: "bar", proposed_text: "bar", document_id: document.id, file_index: 2} |> Repo.insert!()
|
||||
%Translation{revision_id: revision.id, key: "test", corrected_text: "foo", proposed_text: "foo", document_id: document.id, file_index: 1} |> Repo.insert!()
|
||||
if Langue.Formatter.Rails.enabled?() do
|
||||
test "export with language overrides", %{conn: conn, project: project, revision: revision, language: language} do
|
||||
revision = Repo.update!(Ecto.Changeset.change(revision, %{slug: "testtest"}))
|
||||
document = %Document{project_id: project.id, path: "test2", format: "rails_yml"} |> Repo.insert!()
|
||||
%Translation{revision_id: revision.id, key: "ok", corrected_text: "bar", proposed_text: "bar", document_id: document.id, file_index: 2} |> Repo.insert!()
|
||||
%Translation{revision_id: revision.id, key: "test", corrected_text: "foo", proposed_text: "foo", document_id: document.id, file_index: 1} |> Repo.insert!()
|
||||
|
||||
params = %{order_by: "", project_id: project.id, language: language.slug, document_format: document.format, document_path: document.path}
|
||||
params = %{order_by: "", project_id: project.id, language: language.slug, document_format: document.format, document_path: document.path}
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get(export_jipt_path(conn, [], params))
|
||||
response =
|
||||
conn
|
||||
|> get(export_jipt_path(conn, [], params))
|
||||
|
||||
assert response.resp_body == """
|
||||
"testtest":
|
||||
"ok": "{^ok@test2}"
|
||||
"test": "{^test@test2}"
|
||||
"""
|
||||
assert response.resp_body == """
|
||||
"testtest":
|
||||
"ok": "{^ok@test2}"
|
||||
"test": "{^test@test2}"
|
||||
"""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user