Странная ошибка при переводе слова «админ» в Rails - PullRequest
0 голосов
/ 22 февраля 2020

Обратите внимание на следующий вывод консоли:

$ grep -IirF admin config/locales/
config/locales/static.el.yml:  Administered: Χορηγήθηκε
config/locales/el.yml:  admin: διαχειριστής
config/locales/system.el.yml:        administered: Χορηγήθηκε

$ rails c
Running via Spring preloader in process 8176
Loading development environment (Rails 6.0.2.1)
irb(main):001:0> helper.t('admin1', locale: :el)
=> "admin1"
irb(main):002:0> helper.t('admin', locale: :el)
=> "διαχειριστής"
irb(main):003:0> helper.t('admin1', locale: :en)
=> "admin1"
irb(main):004:0> helper.t('admin', locale: :en)
=> {:js=>{true=>true, false=>false, :is_present=>"Is present", :is_blank=>"Is blank", :date=>"Date ...", :between_and_=>"Between ... and ...", :today=>"Today", :yesterday=>"Yesterday", :this_week=>"This week", :last_week=>"Last week", :number=>"Number ...", :contains=>"Contains", :is_exactly=>"Is exactly", :starts_with=>"Starts with", :ends_with=>"Ends with", :too_many_objects=>"Too many objects, use search box above", :no_objects=>"No objects found"}, :loading=>"Loading...", :toggle_navigation=>"Toggle navigation", :home=>{:name=>"Home"}, :pagination=>{:previous=>"&laquo; Prev", :next=>"Next &raquo;", :truncate=>"…"}, :misc=>{:search=>"Search", :filter=>"Filter", :refresh=>"Refresh", :show_all=>"Show all", :add_filter=>"Add filter", :bulk_menu_title=>"Selected items", :remove=>"Remove", :add_new=>"Add new", :chosen=>"Chosen %{name}", :chose_all=>"Choose all", :clear_all=>"Clear all", :up=>"Up", :down=>"Down", :navigation=>"Navigation", :root_navigation=>"Actions", :navigation_static_label=>"Links", :log_out=>"Log out", :time_ago=>"%{time} ago", :ago=>"ago", :more=>"Plus %{count} more %{models_name}"}, :flash=>{:successful=>"%{name} successfully %{action}", :error=>"%{name} failed to be %{action}", :noaction=>"No actions were taken", :model_not_found=>"Model '%{model}' could not be found", :object_not_found=>"%{model} with id '%{id}' could not be found"}, :table_headers=>{:model_name=>"Model name", :last_created=>"Last created", :records=>"Records", :username=>"User", :changes=>"Changes", :created_at=>"Date/Time", :item=>"Item", :message=>"Message"}, :actions=>{:dashboard=>{:title=>"Site Administration", :menu=>"Dashboard", :breadcrumb=>"Dashboard"}, :index=>{:title=>"List of %{model_label_plural}", :menu=>"List", :breadcrumb=>"%{model_label_plural}"}, :show=>{:title=>"Details for %{model_label} '%{object_label}'", :menu=>"Show", :breadcrumb=>"%{object_label}"}, :show_in_app=>{:menu=>"Show in app"}, :new=>{:title=>"New %{model_label}", :menu=>"Add new", :breadcrumb=>"New", :link=>"Add a new %{model_label}", :done=>"created"}, :edit=>{:title=>"Edit %{model_label} '%{object_label}'", :menu=>"Edit", :breadcrumb=>"Edit", :link=>"Edit this %{model_label}", :done=>"updated"}, :delete=>{:title=>"Delete %{model_label} '%{object_label}'", :menu=>"Delete", :breadcrumb=>"Delete", :link=>"Delete '%{object_label}'", :done=>"deleted"}, :bulk_delete=>{:title=>"Delete %{model_label_plural}", :menu=>"Multiple delete", :breadcrumb=>"Multiple delete", :bulk_link=>"Delete selected %{model_label_plural}"}, :export=>{:title=>"Export %{model_label_plural}", :menu=>"Export", :breadcrumb=>"Export", :link=>"Export found %{model_label_plural}", :bulk_link=>"Export selected %{model_label_plural}", :done=>"exported"}, :history_index=>{:title=>"History for %{model_label_plural}", :menu=>"History", :breadcrumb=>"History"}, :history_show=>{:title=>"History for %{model_label} '%{object_label}'", :menu=>"History", :breadcrumb=>"History"}}, :form=>{:cancel=>"Cancel", :basic_info=>"Basic info", :required=>"Required", :optional=>"Optional", :one_char=>"character", :char_length_up_to=>"length up to", :char_length_of=>"length of", :save=>"Save", :save_and_add_another=>"Save and add another", :save_and_edit=>"Save and edit", :all_of_the_following_related_items_will_be_deleted=>"? The following related items may be deleted or orphaned:", :are_you_sure_you_want_to_delete_the_object=>"Are you sure you want to delete this %{model_name}", :confirmation=>"Yes, I'm sure", :bulk_delete=>"The following objects will be deleted, which may delete or orphan some of their related dependencies:", :new_model=>"%{name} (new)"}, :export=>{:confirmation=>"Export to %{name}", :select=>"Select fields to export", :select_all_fields=>"Select All Fields", :fields_from=>"Fields from %{name}", :fields_from_associated=>"Fields from associated %{name}", :display=>"Display %{name}: %{type}", :options_for=>"Options for %{name}", :empty_value_for_associated_objects=>"<empty>", :click_to_reverse_selection=>"Click to reverse selection", :csv=>{:header_for_root_methods=>"%{name}", :header_for_association_methods=>"%{name} [%{association}]", :encoding_to=>"Encode to", :encoding_to_help=>"Choose output encoding. Leave empty to let current input encoding untouched: (%{name})", :skip_header=>"No header", :skip_header_help=>"Do not output a header (no fields description)", :default_col_sep=>",", :col_sep=>"Column separator", :col_sep_help=>"Leave blank for default ('%{value}')"}}, :history_rollback=>{:cancel=>"Cancel", :confirm=>"Are you sure?", :table_headers=>{:changes=>"Changes", :field=>"Field", :rollback=>"Rollback", :view_changes=>"View changes"}, :rollback_destroy=>"Rolled back newly-created record by destroying it.", :rollback_success=>"Rolled back changes to this record.", :rollback_impossible=>"Couldn't rollback. Sorry.", :version_not_found=>"Version does not exist.", :rollback_violates_foreign_key=>"Couldn't rollback: this model links to another model, which doesn't exists."}}

Перевод, кажется, работает правильно, за исключением одного слова: 'admin'

Может кто-нибудь объяснить эту ошибку и как ее преодолеть

1 Ответ

1 голос
/ 12 марта 2020

Скорее всего, это связано с конфликтом с другим гемом, который добавляет пространство имен администратора, например, ActiveAdmin или rails_admin, или плагином авторизации ролей. Вот почему он возвращает ха sh вместо единственного строкового значения.

Какой-то другой код или гем загрузил ключ admin, чтобы он выглядел примерно так:

en:
  admin:
    js:
      'true': true
      'false': false
      is_present: Is present
      ....etc....

I предложил бы вложить ваш ключ, чтобы избежать конфликта с чем-то вроде:

en:
  user_type:
    admin: Administrator
helper.t('user_type.admin')

Я бы также предложил настроить гем i18n-tasks , который может находить и устранять проблемы с файлы перевода, как часть вашего CI или набора тестов, который, я считаю, обнаружил бы этот конфликт с помощью команды i18n-tasks health и показал, что admin является дублирующим ключом, поэтому, когда ваши файлы yaml и гем объединяются, только последний, кто напишет в переводы, ха sh будет сохранен.

...