How do you get 301 Error on purpose?
Tuesday, Week 5, Day 16 Jen, Steph, Rob, Wale, Jalil and Mike McCormick.
We met up at a coffee shop and worked on the narrative for a while. Mainly we started talking about the 301 Error. Jen had spent the day trying to get the 301 error in the terminal like we will want Emerald, our user, to get. This turns out to be harder than we thought.
One of our thoughts is that maybe a 301 error is not returned to the terminal because you are either redirected and get a 200 success code or you are not redirected and you get a 404 error.
We spent a good portion of the night investigating this idea and are only a little closer to the solution.
Another thought is that maybe we need to use the method get_response instead of just get.
Things we tried. Jen set up a redirected page on her site. but it doesnt return a 301 error.
One of the cool things Mike McCormick showed us is to create a yaml file in the config/locale where we insert our code, use erb, embeded ruby, to insert it into our file. We use the translate method in the yaml and the test. So we can change the text and the tests will still pass. Previously we were hard coding our text in the test.
Our test for this objective now looks like this:
require 'rails_helper' feature "Emerald visits adventure 1 objective 1" do scenario "emerald reads narrative" do visit '/adventures/1/objectives/1' expect(page).to have_content I18n.t("adventure.one.objective1.copy") end end
The embeded Ruby in our show page which displays the copy we put in our yaml file.
The copy in our yaml file
en: adventure: one: objective1: copy: " our copy blah blah blah "
Internationalization - I18n - I (18 letters) n
We used the I18n gem included in Rails to translates our text.
In computing, internationalization and localization are means of adapting computer software to different languages, regional differences and technical requirements of a target market.
Internationalization is the process of designing a software application so that it can potentially be adapted to various languages and regions without engineering changes.
Localization is the process of adapting internationalized software for a specific region or language by adding locale-specific components and translating text.
Localization (which is potentially performed multiple times, for different locales) uses the infrastructure or flexibility provided by internationalization (which is ideally performed only once, or as an integral part of ongoing development).
The Rails gem I18n has it's specific uses.
The most important methods of the I18n API are:
translate # Lookup text translations localize # Localize Date and Time objects to local formats These have the aliases #t and #l so you can use them like this:
I18n.t 'store.title' I18n.l Time.now
(18 stands for the number of letters between the first i and last n in internationalization)
YAML Syntax References (http://docs.ansible.com/YAMLSyntax.html) (http://symfony.com/doc/current/components/yaml/yaml_format.html)