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

Localize the models #397

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/models/conversation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ class Conversation < ApplicationRecord
def self.grouped_by_increasing_time_interval_for_user(user)
nav_conversations = user.conversations.ordered

keys = ["Today", "Yesterday", "This Week", "This Month", "Last Month", "Older"]
keys = [
I18n.t('models.conversation.groupings.today'),
I18n.t('models.conversation.groupings.yesterday'),
I18n.t('models.conversation.groupings.this_week'),
I18n.t('models.conversation.groupings.this_month'),
I18n.t('models.conversation.groupings.last_month'),
I18n.t('models.conversation.groupings.older'),
]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a good example of a view consideration sneaking it's way into the model. It'd be really nice if we could push this up to a partial somehow.

One slightly hacky way to do it would be to turn these keys into symbols rather than strings—or even better, we turn these into the strings that represent the i18n name! So this array would be: keys = [ ".today", ".yesterday" ...] and then the view which iterates over these keys (somewhere we must have .each do |header, _| we do display it with <%= t header %>

I got this hack by realizing that views support lazy lookups of keys

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I hear you. I would put any changes of the logic into a separate PR. I cannot add issues, so maybe it's something you could do so that it doesn't get forgotten :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

Done: #439

values = [
nil,
Date.current.beginning_of_day,
Expand Down
2 changes: 1 addition & 1 deletion app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def set_default_bytes
end

def file_present
errors.add(:file, "must be attached") unless file.attached?
errors.add(:file) unless file.attached?
end

def wait_for_file_variant_to_process!(variant)
Expand Down
4 changes: 2 additions & 2 deletions app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def create_conversation
end

def validate_conversation
errors.add(:conversation, 'is invalid') unless conversation.user == Current.user
errors.add(:conversation) unless conversation.user == Current.user
end

def validate_assistant
errors.add(:assistant, 'is invalid') unless assistant.user == Current.user
errors.add(:assistant) unless assistant.user == Current.user
end

def start_assistant_reply
Expand Down
4 changes: 2 additions & 2 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class Person < ApplicationRecord

def personable_id_unchanged
if personable_id_changed? && persisted?
errors.add(:personable_id, "cannot be changed after creation")
errors.add(:personable_id)
end
end

def proper_personable_id
if personable_id.present? && personable.id.blank?
errors.add(:personable_id, 'must be provided on update')
errors.add(:personable_id)
end
end
end
12 changes: 6 additions & 6 deletions app/views/authentications/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
<%= image_tag("logo.svg", width: "24", height: "24", class: "text-gray-950") %>
</div>

<h2 class="text-3xl font-semibold">Welcome back</h2>
<h2 class="text-3xl font-semibold"><%= t('.welcome_back') %></h2>

<% if Feature.registration? %>
<span class="text-sm text-center">
Don't have an account? <%= link_to "Sign up", register_path, class: "underline" %>
<%= t('.dont_have_an_account') %>&nbsp;<%= link_to t('.sign_up'), register_path, class: "underline" %>
</span>
<% end %>

<% if Feature.google_authentication? %>
<%= button_to "Log In with Google", "/auth/google",
<%= button_to t('.login_with_google'), "/auth/google",
method: "post",
class: %|
text-white font-medium
Expand All @@ -39,16 +39,16 @@
value: params[:email],
id: "email",
autofocus: params[:email].present? ? false : true,
placeholder: "Email address",
placeholder: t('.email_address'),
class: "border border-gray-400 rounded p-3 dark:text-black"
%>
<%= f.password_field :password,
id: "password",
autofocus: params[:email].present? ? true : false,
placeholder: "Password",
placeholder: t('.password'),
class: "border border-gray-400 rounded p-3 dark:text-black"
%>
<%= f.submit "Log In",
<%= f.submit t('.login'),
class: %|
text-white font-medium
bg-brand-blue dark:bg-gray-900
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
|
} do %>
<%= icon "cog-6-tooth", variant: :outline, size: 18 %>
Settings
<%= t('.settings') %>
<% end %>
</li>
<li><%= link_to logout_path, data: { turbo: false } do %><%= icon "arrow-right-start-on-rectangle", variant: :outline, size: 18 %>Logout<% end %></li>
<li><%= link_to logout_path, data: { turbo: false } do %><%= icon "arrow-right-start-on-rectangle", variant: :outline, size: 18 %><%= t('.logout') %><% end %></li>
</menu>
</div>
</footer>
Expand Down
6 changes: 3 additions & 3 deletions app/views/layouts/settings.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% content_for :title, "Settings — HostedGPT" %>
<% content_for :title, "#{t('.settings')} — HostedGPT" %>
<% content_for :nav_column do %>
<header class="pl-2 py-7 text-3xl relative">
<%= link_to root_path, class: "inline-block cursor-pointer py-1 pt-0 align-middle" do %>
Expand All @@ -13,7 +13,7 @@
tooltip: :bottom
%>
<% end %>
Settings
<%= t('.settings') %>
</header>
<section id="menu" data-controller="radio-behavior" data-radio-behavior-selected-class="relationship">
<% @settings_menu.each do |controller, settings_items| %>
Expand Down Expand Up @@ -41,7 +41,7 @@
stroke-2
text-zinc-600 group-hover:text-zinc-900 dark:text-zinc-400 dark:group-hover:text-white
|,
title: "Close",
title: t('.close'),
tooltip: :left
%>
<% end %>
Expand Down
10 changes: 5 additions & 5 deletions app/views/settings/language_models/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1 class="text-3xl">Language Models</h1>
<h1 class="text-3xl"><%= t('.language_models') %></h1>

<p class="my-8">
<%= link_to "Add New",
<%= link_to t('.add_new'),
new_settings_language_model_path,
class: %| inline-block font-bold
bg-gray-200 dark:bg-gray-900
Expand All @@ -14,9 +14,9 @@
<table id="language-models" class="w-full table-auto border-b border-gray-300">
<thead>
<tr class="bg-gray-200">
<th>Name</th>
<th>Description</th>
<th>API Service</th>
<th><%= t('.name') %></th>
<th><%= t('.description') %></th>
<th><%= t('.api_service') %></th>
</tr>
</thead>

Expand Down
11 changes: 5 additions & 6 deletions app/views/settings/memories/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<div class="mx-auto md:w-2/3 w-full">
<h1 class="text-3xl">Assistant Memories</h1>
<h1 class="text-3xl"><%= t('.assistent_memories') %></h1>
<p class="pt-3">
These are the things remembered from all past conversations. All assistants
share this memory.
<%= t('.explanation') %>
</p>

<p class="py-3">
<% if @memories.length == 0 %>
<span class="font-bold">No memories</span>
<span class="font-bold"><%= t('.no_memories') %></span>
<% else %>
<%= button_to 'Clear All Memories',
<%= button_to t('.clear_all_memories'),
settings_memories_path,
form_class: "pb-3",
class: %|
Expand All @@ -20,7 +19,7 @@
cursor-pointer
|,
method: :delete,
data: { turbo_confirm: 'Are you sure?' }
data: { turbo_confirm: t('.are_you_sure') }
%>
<% end %>
</p>
Expand Down
26 changes: 13 additions & 13 deletions app/views/settings/people/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<% end %>

<div class="my-5" data-controller="transition" data-transition-toggle-class="hidden">
<%= user_fields.label :dark_mode, "Color Theme" %>
<%= user_fields.label :dark_mode %>
<div class="flex items-center justify-between outline-none pl-3 py-2 mt-2 w-full dark:text-black gap-1">
<%= user_fields.fields_for :preferences do |preferences_fields| %>
<% %w(dark light system).each do |value| %>
Expand All @@ -57,17 +57,17 @@

<% if Feature.google_tools? %>
<div class="my-5" data-controller="transition" data-transition-toggle-class="hidden">
<%= user_fields.label "Enable Tools for Assistants", "Enable Tools for Assistants" %>
<%= user_fields.label t('.enable_tools_for_assistants') %>

<div class="flex items-center justify-between outline-none py-2 mt-2 w-full dark:text-black gap-1">
<div class="dark:text-gray-400 border-l-4 border-gray-100 dark:border-gray-600 pl-5 pr-1">
Enable <span class="font-semibold">Gmail</span><br>
Trouble? <%= link_to "Delete app connection", "https://myaccount.google.com/connections", target: "_blank", class: "underline" %>
<%= t('.enable') %>&nbsp;<span class="font-semibold">Gmail</span><br>
<%= t('.trouble') %>&nbsp;<%= link_to t('.delete_app_connection'), "https://myaccount.google.com/connections", target: "_blank", class: "underline" %>
</div>
<% if Current.user.gmail_credential %>
<div class="text-green-700 font-bold">Enabled</div>
<div class="text-green-700 font-bold"><%= t('.enabled') %></div>
<% else %>
<%= form.label :authorize_gmail, "Authorized Gmail",
<%= form.label :authorize_gmail, t('.authorize_gmail'),
class: %|
inline-block font-medium
bg-gray-100 dark:bg-gray-900 dark:text-white
Expand All @@ -81,13 +81,13 @@

<div class="flex items-center justify-between outline-none py-2 mt-2 w-full dark:text-black gap-1">
<div class="dark:text-gray-400 border-l-4 border-gray-100 dark:border-gray-600 pl-5 pr-1">
Enable <span class="font-semibold">Google Tasks</span><br>
Trouble? <%= link_to "Delete connection", "https://myaccount.google.com/connections", target: "_blank", class: "underline" %>
<%= t('.enable') %>&nbsp;<span class="font-semibold">Google Tasks</span><br>
<%= t('.trouble') %>&nbsp;<%= link_to t('.delete_app_connection'), "https://myaccount.google.com/connections", target: "_blank", class: "underline" %>
</div>
<% if Current.user.google_tasks_credential %>
<div class="text-green-700 font-bold">Enabled</div>
<div class="text-green-700 font-bold"><%= t('.enabled') %></div>
<% else %>
<%= form.label :authorize_google_tasks, "Authorized Google Tasks",
<%= form.label :authorize_google_tasks, t('.authorize_google_tasks'),
class: %|
inline-block font-medium
bg-gray-100 dark:bg-gray-900 dark:text-white
Expand All @@ -105,17 +105,17 @@
<% end %>

<div class="inline">
<%= form.submit "Save",
<%= form.submit t('.save'),
class: %|
inline-block font-bold
bg-gray-200 dark:bg-gray-900
border border-gray-400
rounded-lg py-3 px-5
cursor-pointer
|,
data: { turbo_submits_with: "Saving..." }
data: { turbo_submits_with: t('.saving') }
%>
<%= link_to "Cancel", root_path, class: "float-right inline-block ml-5 py-3" %>
<%= link_to t('.cancel'), root_path, class: "float-right inline-block ml-5 py-3" %>
</div>
<% end # form %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/settings/people/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="mx-auto md:w-2/3 w-full">
<h1 class="text-3xl">Your Account</h1>
<h1 class="text-3xl"><%= t('.your_account') %></h1>

<%= render "form", person: Current.person %>
</div>
24 changes: 12 additions & 12 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="p-3 bg-white border border-gray-100 rounded-full">
<%= image_tag("logo.svg", width: "24", height: "24", class: "text-gray-950") %>
</div>
<h2 class='text-3xl font-semibold'>Create your account</h2>
<h2 class='text-3xl font-semibold'><%= t('.create_your_account') %></h2>

<% if @person.errors.any? %>
<div id="error_explanation" class="px-3 py-2 mt-3 font-medium text-red-500 rounded-lg bg-red-50">
Expand All @@ -15,7 +15,7 @@
<% end %>

<% if Feature.google_authentication? %>
<%= button_to "Sign Up with Google", "/auth/google",
<%= button_to t('.signup_with_google'), "/auth/google",
method: "post",
class: %|
text-white font-medium
Expand All @@ -31,7 +31,7 @@
}
%>
<span class="text-sm text-center <%= Feature.disabled?(:password_authentication) && 'hidden' %>">
- Or -
- <%= t('.or') %> -
</span>
<% end %>

Expand All @@ -48,10 +48,10 @@
<%= f.hidden_field :personable_type, id: "personable_type", value: "User" %>

<%= f.label :email, class: "input input-bordered flex items-center justify-between" do %>
<span>Email <span class="">*</span></span>
<span><%= t('.email') %><span class="">*</span></span>
<%= f.email_field :email,
autofocus: true,
placeholder: "Email",
placeholder: t('.email'),
class: "w-44 border-0 dark:text-black"
%>
<% end %>
Expand All @@ -60,9 +60,9 @@
<%= user_fields.fields_for :credentials_attributes, @person.personable.credentials.build, index: "0" do |credential_fields| %>
<%= credential_fields.hidden_field :type, value: "PasswordCredential" %>
<%= credential_fields.label :password, class: "input input-bordered flex items-center justify-between" do %>
<span>Password <span class="">*</span></span>
<span><%= t('.password') %><span class="">*</span></span>
<%= credential_fields.password_field :password,
placeholder: "Password",
placeholder: t('.password'),
class: "w-44 border-0 dark:text-black",
data: { action: "focus->transition#toggleClassOn" }
%>
Expand All @@ -80,15 +80,15 @@
>

<%= user_fields.label :name, class: "input input-bordered flex items-center justify-between" do %>
<span>Full Name <span class="">*</span></span>
<span><%= t('.fullname') %><span class="">*</span></span>
<%= user_fields.text_field :name,
placeholder: "First & Last name",
placeholder: t('.first_and_lastname'),
class: "w-44 border-0 dark:text-black"
%>
<% end %>
</div>
<% end %>
<%= f.submit "Sign Up",
<%= f.submit t('.signup'),
class: %|
text-white font-medium
bg-brand-blue dark:bg-gray-900
Expand All @@ -103,7 +103,7 @@
<% end %>

<span class="text-sm text-center">
Already have an account?
<%= link_to "Log in", login_path, class: "underline" %>
<%= t('.already_have_an_account') %>
<%= link_to t('.login'), login_path, class: "underline" %>
</span>
</div>
5 changes: 4 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
config.assets.quiet = true

# Raises error for missing translations.
# config.i18n.raise_on_missing_translations = true
config.i18n.raise_on_missing_translations = true

# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true
Expand All @@ -82,4 +82,7 @@
config.web_console.permissions = ["192.168.0.0/16", "172.17.0.0/16"]

config.hosts << ENV["DEV_HOST"] if ENV["DEV_HOST"].present?

# Uncomment if you want to force a different locale during development
config.i18n.default_locale = :de
end
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@

# Raise error when a before_action's only/except options reference missing actions
config.action_controller.raise_on_missing_callback_actions = true

# Set the default locale to 'en' when running tests
config.i18n.default_locale = :en
end
Loading
Loading