Skip to content
Open
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
19 changes: 19 additions & 0 deletions app/controllers/rails_i18n_manager/translations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ def translate_missing
redirect_to url, notice: "Translated #{translated_count} of #{total_missing} total missing translations"
end

def new
@translation_key = TranslationKey.new
end

def create
@translation_key = TranslationKey.new(create_params)

if @translation_key.save
redirect_to translation_path(@translation_key[:id]), notice: "Create success."
else
flash.now.alert = "Create failed."
render :new
end
end

private

def get_translation_key
Expand All @@ -200,6 +215,10 @@ def allowed_params
params.require(:translation_key).permit(translation_values_attributes: [:id, :locale, :translation])
end

def create_params
params.require(:translation_key).permit(:key, :translation_app_id)
end

def apply_filters
if params[:app_name].present?
@translation_keys = @translation_keys.joins(:translation_app).where(TranslationApp.table_name => {name: params[:app_name]})
Expand Down
12 changes: 12 additions & 0 deletions app/views/rails_i18n_manager/translations/_new_form.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- view_mode = params[:action] == "show"

= custom_form_for @translation_key, url: translations_path, method: :post, defaults: { view_mode: view_mode, field_layout: :horizontal } do |f|
.form-group
= f.label :translation_app_id, "App Name"
= f.field :translation_app_id, type: :select, collection: RailsI18nManager::TranslationApp.order(name: :asc).pluck(:name, :id)
= f.label :key, "New Key"
= f.text_field :key, label: "New Key", class: "form-control", placeholder: "Enter key"
.form-group
.col-lg-offset-2.col-md-offset-2.col-sm-offset-3.col-lg-10.col-md-10.col-sm-9
button.btn.btn-primary type="submit" Save
= link_to "Cancel", { action: :index }, class: 'btn btn-secondary space-left2'
1 change: 1 addition & 0 deletions app/views/rails_i18n_manager/translations/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.pull-right
= link_to "New translation", new_translation_path, class: "btn btn-primary btn-sm space-right2"
= link_to "Translate with Google", params.to_unsafe_h.merge(action_name: :translate_missing), class: "btn btn-primary btn-sm", "data-confirm" => "Are you sure you want to proceed with translating the missing translations in the currently filtered list?"
= link_to "Import Translations", import_translations_path, class: "btn btn-secondary btn-sm space-left2"
= link_to "Delete Inactive", params.to_unsafe_h.merge(action_name: :delete_inactive_keys), class: "btn btn-danger btn-sm space-left2", data: {confirm: "Warning! This is a highly destructive action.\n\nIts possible to incorrectly upload an incomplete or incorrect file to 'Mark Inactive Translations from Source' which can leave you with inactive keys that maybe shouldnt have been inactivated.\n\nPlease proceed only if you are certain that you do not have any keys that are incorrectly marked inactive.\n\nAre you sure you want to proceed with deleting the inactive translations in the currently filtered list?"}
Expand Down
5 changes: 5 additions & 0 deletions app/views/rails_i18n_manager/translations/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
= render "breadcrumbs"

h2.page-title Add a translation

= render "new_form"
Empty file removed config/initializers/.keep
Empty file.
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RailsI18nManager::Engine.routes.draw do
resources :translations, only: [:index, :show, :edit, :update, :destroy] do
resources :translations, only: [:index, :show, :edit, :update, :destroy, :new, :create] do
collection do
post :translate_missing

Expand Down