Skip to content

Commit

Permalink
Use our own namespace in translations
Browse files Browse the repository at this point in the history
We shouldn't presume that we can just use the forms namespace.
  • Loading branch information
koppen committed Jul 29, 2024
1 parent 72d65f5 commit b14e1b4
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 27 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ What does a form control or an input group consist of?
* [ ] Support all Rails form builder tags
* [ ] ARIA!
* [ ] Create a standard set of styles that can be distributed with the gem, so it looks proper - perhaps based on Flowbite?
* [ ] Should I18n scope be "felt", not "form"?


## Glossary and terms
Expand Down
6 changes: 3 additions & 3 deletions lib/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def classes
# - classes: Classes to add to the help element.
#
# - text: The help text to show. If not provided, the text will be looked up
# in the `forms.<object_name>.<attribute>` translation. See #help for more
# in the `felt.<object_name>.<attribute>` translation. See #help for more
# details. To not render the hint, pass +false+ (or any object that
# responds +true+ to +blank?+).
#
Expand All @@ -41,7 +41,7 @@ def render?
#
# 1. The text argument passed to the component. Pass +false+ to not render
# the help element.
# 2. The `help` key in the `forms.<object_name>.<attribute>` translation.
# 2. The `help` key in the `felt.<object_name>.<attribute>` translation.
# 3. The translation value found under
# `helpers.help.<modelname>.<attribute>` (like with
# ActionView::Helpers::FormBuilder#help).
Expand All @@ -63,7 +63,7 @@ def translate(key)
end

def translation_scope
[:forms, form.object_name, attribute].join(".")
[:felt, form.object_name, attribute].join(".")
end
end
end
6 changes: 3 additions & 3 deletions lib/hint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def classes
# - classes: Classes to add to the hint element.
#
# - text: The hint text to show. If not provided, the text will be looked up
# in the `forms.<object_name>.<attribute>` translation. See #hint for more
# in the `felt.<object_name>.<attribute>` translation. See #hint for more
# details. To not render the hint, pass +false+ (or any object that
# responds +true+ to +blank?+).
#
Expand All @@ -43,7 +43,7 @@ def render?
#
# 1. The text argument passed to the component. Pass +false+ to not render
# the hint element.
# 2. The `hint` key in the `forms.<object_name>.<attribute>` translation.
# 2. The `hint` key in the `felt.<object_name>.<attribute>` translation.
# 3. The translation value found under
# `helpers.hint.<modelname>.<attribute>` (like with
# ActionView::Helpers::FormBuilder#hint).
Expand All @@ -65,7 +65,7 @@ def translate(key)
end

def translation_scope
[:forms, form.object_name, attribute].join(".")
[:felt, form.object_name, attribute].join(".")
end
end
end
18 changes: 9 additions & 9 deletions lib/input_group/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def error_classes
# Help text is looked up in the following order:
#
# 1. The help argument passed to the component.
# 2. The `help` key in the `forms.<object_name>.<attribute>` translation.
# 2. The `help` key in the `felt.<object_name>.<attribute>` translation.
def help
return false if @help == false

Expand All @@ -72,7 +72,7 @@ def help_classes
# Hints are looked up in the following order:
#
# 1. The hint argument passed to the component.
# 2. The `hint` key in the `forms.<object_name>.<attribute>` translation.
# 2. The `hint` key in the `felt.<object_name>.<attribute>` translation.
def hint
return false if @hint == false

Expand All @@ -94,22 +94,22 @@ def hint_classes
# - classes: CSS classes to add to the wrapping input group element.
#
# - help: The help for the input group. If not provided, the help will be
# looked up in the `forms.<object_name>.<attribute>` translation. See
# looked up in the `felt.<object_name>.<attribute>` translation. See
# #help for more details. To not render a help text, pass +false+.
#
# - hint: The hint for the input group. If not provided, the hint will be
# looked up in the `forms.<object_name>.<attribute>` translation. See
# looked up in the `felt.<object_name>.<attribute>` translation. See
# #hint for more details. To not render a hint, pass +false+.
#
# - input_options: The options to pass directly to the input field.
#
# - label: The label text for the input group. If not provided, the text
# will be looked up in the `forms.<object_name>.<attribute>`
# will be looked up in the `felt.<object_name>.<attribute>`
# translation. See #label for more details. To not render the label,
# pass +false+.
#
# - placeholder: The placeholder for the input field. If not provided, the
# placeholder will be looked up in the `forms.<object_name>.<attribute>`
# placeholder will be looked up in the `felt.<object_name>.<attribute>`
# translation. See #placeholder for more details. To disable the
# placeholder, pass an empty string.
#
Expand Down Expand Up @@ -147,7 +147,7 @@ def label_classes
# used:
#
# 1. The label argument passed to the component.
# 2. The `label` key in the `forms.<object_name>.<attribute>` translation.
# 2. The `label` key in the `felt.<object_name>.<attribute>` translation.
# 3. The translation value found under
# `helpers.label.<modelname>.<attribute>` (like with
# ActionView::Helpers::FormBuilder#label).
Expand All @@ -171,7 +171,7 @@ def label?
# Placeholders are looked up in the following order:
#
# 1. The placeholder argument passed to the component.
# 2. The `placeholder` key in the `forms.<object_name>.<attribute>`
# 2. The `placeholder` key in the `felt.<object_name>.<attribute>`
# translation.
def placeholder
@placeholder ||=
Expand Down Expand Up @@ -208,7 +208,7 @@ def translate(key)
end

def translation_scope
[:forms, form.object_name, attribute].join(".")
[:felt, form.object_name, attribute].join(".")
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def classes
# - classes: Classes to add to the label element.
#
# - text: The label text to show. If not provided, the text will be
# looked up in the `forms.<object_name>.<attribute>` translation. See
# looked up in the `felt.<object_name>.<attribute>` translation. See
# #label for more details. To not render the label, pass false.
#
# All remaining keyword arguments are passed to the label element. See
Expand All @@ -40,7 +40,7 @@ def render?
#
# 1. The text argument passed to the component. Pass +false+ to not render
# the label.
# 2. The `label` key in the `forms.<object_name>.<attribute>` translation.
# 2. The `label` key in the `felt.<object_name>.<attribute>` translation.
# 3. The translation value found under
# `helpers.label.<modelname>.<attribute>` (like with
# ActionView::Helpers::FormBuilder#label).
Expand All @@ -60,7 +60,7 @@ def translate(key)
end

def translation_scope
[:forms, form.object_name, attribute].join(".")
[:felt, form.object_name, attribute].join(".")
end
end
end
12 changes: 6 additions & 6 deletions test/input_group/common_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_renders_help_from_arguments
@options = {help: "This has priority over translations"}

with_translations({
forms: {
felt: {
"#{@form.object_name}": {
"#{@attribute}": {
help: "Help from translations"
Expand All @@ -167,7 +167,7 @@ def test_renders_help_from_arguments

def test_renders_help_from_translations
with_translations({
forms: {
felt: {
"#{@form.object_name}": {
"#{@attribute}": {
help: "Help from translations"
Expand All @@ -184,7 +184,7 @@ def test_renders_help_from_translations
def test_does_not_renders_help_from_translations
@options = {help: false}
with_translations({
forms: {
felt: {
"#{@form.object_name}": {
"#{@attribute}": {
help: "Help from translations"
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_renders_hint_from_arguments
@options = {hint: "This has priority over translations"}

with_translations({
forms: {
felt: {
"#{@form.object_name}": {
"#{@attribute}": {
hint: "Hint from translations"
Expand All @@ -257,7 +257,7 @@ def test_renders_hint_from_arguments

def test_renders_hint_from_translations
with_translations({
forms: {
felt: {
"#{@form.object_name}": {
"#{@attribute}": {
hint: "Hint from translations"
Expand All @@ -275,7 +275,7 @@ def test_does_not_render_a_hint_from_translations
@options = {hint: false}

with_translations({
forms: {
felt: {
"#{@form.object_name}": {
"#{@attribute}": {
hint: "Hint from translations"
Expand Down
2 changes: 1 addition & 1 deletion test/test_help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Felt::HelpTest < ViewComponent::TestCase

test "renders help text from translations" do
with_translations({
forms: {
felt: {
"#{@form.object_name}": {
"#{@attribute}": {
help: "Help from translations"
Expand Down
2 changes: 1 addition & 1 deletion test/test_hint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Felt::HintTest < ViewComponent::TestCase

test "renders hint text from translations" do
with_translations({
forms: {
felt: {
"#{@form.object_name}": {
"#{@attribute}": {
hint: "Hint from translations"
Expand Down

0 comments on commit b14e1b4

Please sign in to comment.