Skip to content

Commit

Permalink
WIP [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
virolea committed Sep 25, 2024
1 parent 06f9fe9 commit 8c7e7a9
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ gem "pg"
gem "sprockets-rails"
gem "rubocop-rails-omakase", require: false
# Start debugger with binding.b [https://github.com/ruby/debug]
# gem "debug", ">= 1.0.0"
gem "debug", ">= 1.0.0"
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ GEM
connection_pool (2.4.1)
crass (1.0.6)
date (3.3.4)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
drb (2.2.1)
erubi (1.13.0)
globalid (1.2.1)
Expand Down Expand Up @@ -249,6 +252,7 @@ PLATFORMS

DEPENDENCIES
appraisal
debug (>= 1.0.0)
pg
puma
rosetta-rails!
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Rosetta answers those design principles by offering the following features:
- **Texts as translation keys**: Inspired by the [gettext](https://www.gnu.org/software/gettext/) approach, Rosetta uses the texts themselves as translation keys. The language the codebase is written into is the default locale.
- **Key autodiscovery**: New translation keys are automatically discovered and uniquely saved to the database. No more time spent between views and yaml files.
- **A dedicated interface**: Translators can work on a dedicated interface, separated from the codebase. They can search, filter, edit and create translations in a user-friendly environment

Fire and forget

A real-life example speaking louder than words, here is a comparison between the Rails default I18n approach and Rosetta:

Expand Down Expand Up @@ -172,7 +172,6 @@ end
```

### I18n Support

As of now, Rosetta does not integrate with the `i18n` gem as a custom backend. It might be done in the future, however it's been decided to build Rosetta independently for now. You still need to use `i18n` for backwards compatibility of your existing translations, localization, as well as the translations of gems that depend on it.

## License
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/rosetta/locales_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def create
end
end

def edit
@locale = Locale.find(params[:id])
end

private

def ensure_default_locale_exists
Expand Down
39 changes: 39 additions & 0 deletions app/views/rosetta/locales/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div class="sm:flex sm:items-center">
<div class="sm:flex-auto">
<nav class="flex justify-between items-center">
<ol role="list" class="flex items-center space-x-2">
<li>
<%= link_to "Locales", locales_path, class: "text-base font-semibold leading-6 text-indigo-600 hover:text-indigo-900" %>
</li>

<li>
<div class="flex items-center">
<svg class="h-5 w-5 flex-shrink-0 text-gray-900" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true">
<path d="M5.555 17.776l8-16 .894.448-8 16-.894-.448z" />
</svg>

<%= link_to @locale.name, locale_translations_path(@locale), class: "text-base font-semibold leading-6 text-indigo-600 hover:text-indigo-900" %>
</div>
</li>

<li>
<div class="flex items-center">
<svg class="h-5 w-5 flex-shrink-0 text-gray-900" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true">
<path d="M5.555 17.776l8-16 .894.448-8 16-.894-.448z" />
</svg>

<div class="ml-2 text-base font-semibold leading-6 text-gray-900">Edit</div>
</div>
</li>
</ol>

<div class="flex gap-2">
<%= link_to "Back", edit_locale_path(@locale), class: "btn btn-secondary" %>
</div>
</nav>

<p class="mt-2 text-sm text-gray-700">
Edit the locale's name and manage pluralization rules.
</p>
</div>
</div>
5 changes: 4 additions & 1 deletion app/views/rosetta/locales/translations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
</li>
</ol>

<%= button_to "Deploy locale", locale_deploys_path(@locale), class: "btn btn-primary" %>
<div class="flex gap-2">
<%= link_to "Settings", edit_locale_path(@locale), class: "btn btn-secondary" %>
<%= button_to "Deploy locale", locale_deploys_path(@locale), class: "btn btn-primary" %>
</div>
</nav>

<p class="mt-2 text-sm text-gray-700">
Expand Down
14 changes: 12 additions & 2 deletions test/dummy/app/views/pages/home.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,24 @@
<div>
<h3 class="text-lg font-semibold"><%= _ "Available locales" %></h3>
<ul class="list-disc pl-4">
<% Rosetta::Locale.available_locales.each do |locale| %>
<% Rosetta.available_locales.each do |locale| %>
<li><%= _ locale.name %> <%= "(#{_ "default"})" if locale.default? %> - <%= link_to _("Switch"), root_path(locale: locale.code), class: "text-blue-500 hover:underline" %></li>
<% end %>
</ul>
</div>

<div>
<h3 class="font-semibold text-lg"><%= "Numbers" %></h3>
<h3 class="font-semibold text-lg"><%= _ "Pluralization" %></h3>

<ul class="list-disc pl-4 mt-2">
<li>0 <%# _ "message", count: 0 %></li>
<li>1 <%# _ "message", count: 1 %></li>
<li>2 <%# _ "message", count: 2 %></li>
</ul>
</div>

<div>
<h3 class="font-semibold text-lg"><%= _ "Numbers" %></h3>

<ul class="list-disc pl-4 mt-2">
<li><%= _ "One" %></li>
Expand Down

0 comments on commit 8c7e7a9

Please sign in to comment.