1

我对 Ruby 还很陌生,而且我继承了一个大项目;到目前为止,我一直在通过执行以下操作来很好地更改按钮/表单/文本框上的文本:

如果我想将标有“Text here”的对象上的文本更改为不同的内容,我会在整个 rails 项目中搜索带有“Text here”的字符串。通常我会在我的 locales/en.yml 文件中得到一个结果,然后我会更改该文件的相应部分。

但是,在本例中,我有一个带有“输入位置”的文本字段。我想将其更改为“输入地址”所以我搜索了“输入位置”并在我的国际化文件中果然看到了:

helpers:
enter_a_location: "Enter a location"

这是我整个项目中唯一出现此字符串的地方。但无论我将其更改为什么,当我开始我的 Rails 项目时,我都会不断收到“输入位置”。即使我完全删除了整个 enter_a_location ,它仍然会出现。真的很烦人!我以为我掌握了这个编程业务的窍门。有什么想法吗?

出现“输入位置”的代码部分是(在 text_field 部分中):

<div class='address-area'>

<%= form_for current_user, :url => update_address_path, :html => {:method => :post, :class => 'form-horizontal', :id => 'address_form'} do |f| %>
  <%= f.text_field :address, :id => 'address_autocomplete' %>
  <%= f.hidden_field :city %>
  <%= f.hidden_field :lat  %>
  <%= f.hidden_field :lng  %>

  <%= hidden_field_tag :changed %>
<% end %>

任何帮助,将不胜感激。

这是我的 Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.3'
gem 'rake', '~> 0.9.5'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql2', '~> 0.3.11'
gem 'json', '~> 1.7.3'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'compass-rails', '~> 1.0.1'
  gem 'bootstrap-sass', '~> 2.0.2'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'therubyracer', '~> 0.10.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platform => :ruby

  gem 'uglifier', '>= 1.0.3'
  gem 'jquery-fileupload-rails'
end

gem 'jquery-rails', '~> 2.0.2'
gem 'inherited_resources', '~> 1.3.1'
gem 'simple_form', '~> 2.0.2'
gem 'will_paginate', '~> 3.0.3'
gem 'bootstrap-will_paginate', '~> 0.0.7'
gem 'has_scope', '~> 0.5.1'
gem "best_in_place", "~> 1.1.2"

gem 'devise', '~> 2.0.4'
gem 'omniauth'
gem 'omniauth-facebook'
gem 'linkedin'
gem 'omnicontacts', '~> 0.2.3'
gem 'SystemTimer', '~> 1.2.3'
gem 'resque', '~> 1.20.0'
gem 'resque-scheduler', :require => 'resque_scheduler'
gem 'rest-client', '~> 1.6.7'
gem 'rest-graph', '~> 2.0.1'

gem 'geokit', '=1.6.5'
gem 'geokit-rails3', '~> 0.1.5'
gem 'memcache-client'

gem 'forgery', '~> 0.5.0'
gem 'factory_girl_rails', '~> 1.7.0'
gem "amoeba", "~> 1.2.1"

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug'

group :development do
  gem 'mongrel'
  gem 'pry-rails'
  gem 'quiet_assets'
  gem 'email_spec'
  gem 'capistrano', '~> 2.12.0'
  gem 'capistrano-ext', '~> 1.2.1'
  gem 'ruby-debug-base', '=0.10.4'
  gem 'ruby-debug', '=0.10.4'
  gem 'annotate'
  gem 'letter_opener', :git => 'https://github.com/ryanb/letter_opener.git'
  gem 'localtunnel'
end

group :test do
  gem 'cucumber-rails', '~> 1.3.0', :require => false
  gem 'capybara-webkit', '~> 0.11.0'
  gem 'headless', '~> 0.3.1'
  gem 'database_cleaner', '~> 0.7.2'
  gem 'rspec-rails', '~> 2.9.0'
  gem 'email_spec'
end
4

1 回答 1

3

In some cases if the I18n module doesn't find the translation ( e.g. form attributes ) it falls back to a 'humanized' conversion of the translation's key. For instance 'enter_a_location' -> 'Enter a location'. So you wouldn't know whether it was using the set translation or fallbacking.

Or as Sascha mentioned it could be that another gem/engine/plugin you are using has the exact same translation key and is overriding the one you have set.

Right now it's hard to tell, because we can't see where the assignment of 'enter_a_location' is happening.

于 2013-04-07T13:00:46.483 回答