Open bruce opened 10 years ago
@bruce I have started using vex, and it will be good to have internationalizatio, do you have any plans about it?
@wafcio, this should be helpful - https://github.com/CargoSense/vex#error-message-renderers
unfortunatelly it isn't because you have injected counters and different variables to error message, which make impossible to create translation for them.
I don't understand the trouble. Can you write an example for me?
when I checked length validator I received must have a length of at least 2
string instead of must have a length of at least %{count}
I don't see why it can't be achieved. Can you drop the code snippet and point the current and expected behavior?
What if you have different lenght in different places like min: 2
, min: 4
or you change 2 to 3 for example, then you need to fill new translation key. Don't you think that it will be better to have %{count}
like it is resolved in ecto?
Sorry, I don't really get what you mean by "need to fill new translation key". Some examples of code would definitely help here.
Anyway I think this link I posted above still would be useful, because with error renderer you can create any error that you need.
If you need no translation or no interpolation, and want to receive original message like ecto changeset does: {"should be at least %{count} characters", [count: 3, validation: :length, min: 3]}
, try write new error renderer.
defmodule MyRenderer do
@behaviour Vex.ErrorRenderer
def message(options, _default, context \\ []), do: {options[:message], context}
end
result = Vex.validate([name: "Foo"], name: [
length: [
min: 4,
error_renderer: MyRenderer,
message: "too short, min %{min} chars"
]
])
assert {:error, [{:error, :name, :length, {"too short, min %{min} chars", [min: 4, ...]}}]} = result
I'm not fully sure is it target your issues, and if not, please, drop some snippet of code.
Probably using: https://github.com/chrismccord/linguist