Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for strings in gems #45

Merged
merged 2 commits into from
Nov 4, 2024
Merged

Conversation

coorasse
Copy link
Member

@coorasse coorasse commented Nov 2, 2024

This PR adds support for both strings coming from gems and strings not yet translated in the current language.
It enables to widen much more the range of strings that is possible to translate with moirai.

Replaces #32

@coorasse coorasse requested a review from a team as a code owner November 2, 2024 22:04
@coorasse coorasse force-pushed the support_non_existing_translations branch from f139220 to bfa8ff9 Compare November 2, 2024 22:05
@coorasse coorasse self-assigned this Nov 4, 2024
Copy link
Contributor

@CuddlyBunion341 CuddlyBunion341 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!
Quite a large PR but I am very happy with the refactoring that has been done and the tests that have been written.

@@ -1,3 +1,8 @@
## Unreleased
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea to include unreleased changes in the CHANGELOG 👍🏻

README.md Outdated Show resolved Hide resolved
else
redirect_back_or_to moirai_translation_files_path, status: :unprocessable_entity
end
redirect_back_or_to moirai_translation_files_path, status: :unprocessable_entity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this simplification

locale ||= I18n.locale
moirai_translations[locale.to_sym][key]
moirai_translations[locale.to_sym].select do |_filename, data|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not filter_map?

Suggested change
moirai_translations[locale.to_sym].select do |_filename, data|
moirai_translations[locale.to_sym].filter_map { |filename, data| filename if data.dig(*key.split(".")).present? }
.sort_by { |file_path| file_path.start_with?(Rails.root.to_s) ? 0 : 1 }

@@ -15,12 +15,25 @@ def call
changes
end

def best_file_path_for(key, locale)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!


visit "/?locale=de&moirai=true"
refute_key_editable page, "buttons.very.much.nested.only_english"
refute_key_editable page, "buttons.very.much.nested.only_italian"
assert_key_editable page, "buttons.very.much.nested.only_english"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice assertion helpers!

@@ -3,6 +3,7 @@
Moirai::Engine.routes.draw do
root to: "translation_files#index"

resources :translations, only: %i[index]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the addition of the translations controller, but I lack a link to it for example from the /moirai page. Would this be something to take into consideration or should we just keep it for debugging purposes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment is very ugly. We could for sure link it, but is also not documented at the moment, so let's keep it for debugging purpose for now.

Co-authored-by: Daniel Bengl <53896675+CuddlyBunion341@users.noreply.github.com>
@coorasse coorasse merged commit ea496e9 into main Nov 4, 2024
2 checks passed
@coorasse coorasse deleted the support_non_existing_translations branch November 4, 2024 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants