diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4e5617f..8b5cb14 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,9 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception before_action :authenticate_user! + before_action :set_locale + + def set_locale + I18n.locale = params[:lang] || I18n.default_locale + end end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 5afc8fc..1ae4d4b 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -1,32 +1,45 @@ class ProductsController < ApplicationController def index - + @products = Product.where(user_id: current_user.id).order('name ASC') end def new - + @product = Product.new end def create - + @product = Product.new(product_params) + @product.user_id = current_user.id + if @product.save + redirect_to products_path + else + render :new + end end def edit - + @product = Product.find(params[:id]) end def update - + @product = Product.find(params[:id]) + if @product.update_attributes(product_params) + redirect_to products_path + else + render :edit + end end def destroy - + @product = Product.find(params[:id]) + @product.destroy unless @product.blank? + redirect_to products_path end private def product_params - params.require(:product).permit(:name, :vat_id) + params.require(:product).permit(:name, :vat_id, :netto_price, :qnt_name) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a284d0e..0bbafea 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -22,4 +22,16 @@ module ApplicationHelper "#{icn}#{name}" end + + def errors_to_html(errors) + ret = '
' + ret += I18n.t('activerecord.errors.messages.record_invalid', errors: errors.count) + ret += '
    ' + errors.full_messages.each do |msg| + ret += "
  • #{msg}
  • " + end + ret += '
' + ret + end + end diff --git a/app/views/customers/_form.html.erb b/app/views/customers/_form.html.erb index 317132d..52e37d4 100644 --- a/app/views/customers/_form.html.erb +++ b/app/views/customers/_form.html.erb @@ -1,17 +1,7 @@ <%= form_for @customer, html: {class: "form-horizontal"} do |f| %> <% if @customer.errors.any? %> -
-

- <%= pluralize(@customer.errors.count, "error") %> prohibited - this article from being saved: -

- -
+ <%= raw errors_to_html(@customer.errors) %> <% end %>
<%= f.label :name, class: "col-sm-2 control-label" %> diff --git a/app/views/customers/edit.html.erb b/app/views/customers/edit.html.erb index 0a22014..9523840 100644 --- a/app/views/customers/edit.html.erb +++ b/app/views/customers/edit.html.erb @@ -1,12 +1,11 @@ -
-
-
-
Edycja klienta
-
- <%= link_to raw(" Powrot"), customers_path, title: 'Powrot' %> -
+
+
+
Edycja klienta
+
+ <%= link_to raw(" " + I18n.t('back')), customers_path, title: I18n.t('back'), class: "text-primary" %>
-
+
+
<%= render 'form' %>
diff --git a/app/views/customers/index.html.erb b/app/views/customers/index.html.erb index 4f6bba5..f46dfa4 100644 --- a/app/views/customers/index.html.erb +++ b/app/views/customers/index.html.erb @@ -30,5 +30,4 @@ <% end %>
-
diff --git a/app/views/customers/new.html.erb b/app/views/customers/new.html.erb index 4b4e5a9..8c7f8ab 100644 --- a/app/views/customers/new.html.erb +++ b/app/views/customers/new.html.erb @@ -1,13 +1,11 @@ -
-
-
+
+
Nowy klient
- <%= link_to raw(" Powrot"), customers_path, title: 'Powrot' %> + <%= link_to raw(" " + I18n.t('back')), customers_path, title: I18n.t('back'), class: "text-primary" %>
-
-
+
+
<%= render 'form' %>
-
diff --git a/config/application.rb b/config/application.rb index 950069e..b6e9294 100644 --- a/config/application.rb +++ b/config/application.rb @@ -11,6 +11,9 @@ module InvoiceKeeper # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. + config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s] + config.i18n.default_locale = :pl + config.assets.paths << Rails.root.join('app', 'assets', 'fonts') config.assets.precompile += %w( .svg .eot .woff .ttf .otf .woff2 ) end diff --git a/config/locales/pl.yml b/config/locales/pl.yml new file mode 100644 index 0000000..de3169f --- /dev/null +++ b/config/locales/pl.yml @@ -0,0 +1,254 @@ +pl: + back: 'Powrót' + save: 'Zapisz' + menu: + dashboard: 'Dashboard' + customers: 'Klienci' + products: 'Produkty' + invoices: 'Faktury' + activerecord: + attributes: + customer: + name: 'Nazwa firmy' + street: 'Adres' + city: 'Miasto' + postcode: 'Kod pocztowy' + nip: 'NIP' + regon: 'Regon' + errors: + messages: + record_invalid: 'Negatywne sprawdzenie poprawności: %{errors}' + restrict_dependent_destroy: + has_many: Nie może zostać usunięte, gdyż istnieją zależne od niego %{record} + has_one: Nie może zostać usunięte, gdyż istnieje zależny od niego %{record} + date: + abbr_day_names: + - nie + - pon + - wto + - śro + - czw + - pią + - sob + abbr_month_names: + - + - sty + - lut + - mar + - kwi + - maj + - cze + - lip + - sie + - wrz + - paź + - lis + - gru + day_names: + - niedziela + - poniedziałek + - wtorek + - środa + - czwartek + - piątek + - sobota + formats: + default: "%d-%m-%Y" + long: "%B %d, %Y" + short: "%d %b" + month_names: + - + - styczeń + - luty + - marzec + - kwiecień + - maj + - czerwiec + - lipiec + - sierpień + - wrzesień + - październik + - listopad + - grudzień + order: + - :day + - :month + - :year + datetime: + distance_in_words: + about_x_hours: + few: około %{count} godziny + many: około %{count} godzin + one: około godziny + other: około %{count} godzin + about_x_months: + few: około %{count} miesiące + many: około %{count} miesięcy + one: około miesiąca + other: około %{count} miesięcy + about_x_years: + few: około %{count} lata + many: około %{count} lat + one: około rok + other: około %{count} lat + almost_x_years: + few: prawie %{count} lata + many: prawie %{count} lat + one: prawie rok + other: prawie %{count} lat + half_a_minute: pół minuty + less_than_x_minutes: + few: mniej niż %{count} minuty + many: mniej niż %{count} minut + one: mniej niż minutę + other: mniej niż %{count} minut + less_than_x_seconds: + few: mniej niż %{count} sekundy + many: mniej niż %{count} sekund + one: mniej niż sekundę + other: mniej niż %{count} sekund + over_x_years: + few: ponad %{count} lata + many: ponad %{count} lat + one: ponad rok + other: ponad %{count} lat + x_days: + few: "%{count} dni" + many: "%{count} dni" + one: 1 dzień + other: "%{count} dni" + x_minutes: + few: "%{count} minuty" + many: "%{count} minut" + one: 1 minuta + other: "%{count} minut" + x_months: + few: "%{count} miesiące" + many: "%{count} miesięcy" + one: 1 miesiąc + other: "%{count} miesięcy" + x_seconds: + few: "%{count} sekundy" + many: "%{count} sekund" + one: 1 sekunda + other: "%{count} sekund" + prompts: + day: Dzień + hour: Godzina + minute: Minuta + month: Miesiąc + second: Sekundy + year: Rok + errors: + format: "%{attribute} %{message}" + messages: + accepted: musi zostać zaakceptowane + blank: nie może być puste + confirmation: nie zgadza się z polem %{attribute} + empty: nie może być puste + equal_to: musi być równe %{count} + even: musi być parzyste + exclusion: jest zarezerwowane + greater_than: musi być większe od %{count} + greater_than_or_equal_to: musi być większe lub równe %{count} + inclusion: nie znajduje się na liście dopuszczalnych wartości + invalid: jest nieprawidłowe + less_than: musi być mniejsze od %{count} + less_than_or_equal_to: musi być mniejsze lub równe %{count} + not_a_number: nie jest liczbą + not_an_integer: musi być liczbą całkowitą + odd: musi być nieparzyste + present: musi być puste + taken: zostało już zajęte + too_long: + few: jest za długie (maksymalnie %{count} znaki) + many: jest za długie (maksymalnie %{count} znaków) + one: jest za długie (maksymalnie jeden znak) + other: jest za długie (maksymalnie %{count} znaków) + too_short: + few: jest za krótkie (przynajmniej %{count} znaki) + many: jest za krótkie (przynajmniej %{count} znaków) + one: jest za krótkie (przynajmniej jeden znak) + other: jest za krótkie (przynajmniej %{count} znaków) + wrong_length: + few: ma nieprawidłową długość (powinna wynosić %{count} znaki) + many: ma nieprawidłową długość (powinna wynosić %{count} znaków) + one: ma nieprawidłową długość (powinna wynosić jeden znak) + other: ma nieprawidłową długość (powinna wynosić %{count} znaków) + other_than: musi być inna niż %{count} + template: + body: 'Błędy dotyczą następujących pól:' + header: + few: "%{model} nie został zachowany z powodu %{count} błędów" + many: "%{model} nie został zachowany z powodu %{count} błędów" + one: "%{model} nie został zachowany z powodu jednego błędu" + other: "%{model} nie został zachowany z powodu %{count} błędów" + helpers: + select: + prompt: Proszę wybrać + submit: + create: Utwórz %{model} + submit: Zapisz %{model} + update: Aktualizuj %{model} + number: + currency: + format: + delimiter: " " + format: "%n %u" + precision: 2 + separator: "," + significant: false + strip_insignificant_zeros: true + unit: zł + format: + delimiter: " " + precision: 3 + separator: "," + significant: false + strip_insignificant_zeros: false + human: + decimal_units: + format: "%n %u" + units: + billion: Miliard + million: Milion + quadrillion: Biliard + thousand: Tysiąc + trillion: Bilion + unit: '' + format: + delimiter: '' + precision: 3 + significant: true + strip_insignificant_zeros: true + storage_units: + format: "%n %u" + units: + byte: + few: bajty + many: bajtów + one: bajt + other: bajty + gb: GB + kb: KB + mb: MB + tb: TB + percentage: + format: + delimiter: '' + format: "%n%" + precision: + format: + delimiter: '' + support: + array: + last_word_connector: " oraz " + two_words_connector: " i " + words_connector: ", " + time: + am: przed południem + formats: + default: "%a, %d %b %Y %H:%M:%S %z" + long: "%B %d, %Y %H:%M" + short: "%d %b %H:%M" + pm: po południu