Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translations seemingly ignored #500

Open
archonic opened this issue May 14, 2015 · 3 comments
Open

Translations seemingly ignored #500

archonic opened this issue May 14, 2015 · 3 comments

Comments

@archonic
Copy link

The app is translating just fine but survey pages are set to the default.

SurveyorController extends ApplicationController where the local is populated, so I don't see why setting the locale in SurveyorController would change anything, but it did. Setting the locale in SurveyorController has the survey pages translate, but the survey content is set to default. The database translation requests (I know there's a PR to remove these) are set to "fr" but are still rendering "en" content:

SurveyTranslation Load (1.7ms)  SELECT  "survey_translations".* FROM "survey_translations" WHERE "survey_translations"."survey_id" = ? AND "survey_translations"."locale" = ?  ORDER BY "survey_translations"."id" ASC LIMIT 1  [["survey_id", 15], ["locale", "fr"]]
  CACHE (0.1ms)  SELECT  "survey_translations".* FROM "survey_translations" WHERE "survey_translations"."survey_id" = ? AND "survey_translations"."locale" = ?  ORDER BY "survey_translations"."id" ASC LIMIT 1  [["survey_id", 15], ["locale", "fr"]]
  CACHE (0.1ms)  SELECT  "survey_translations".* FROM "survey_translations" WHERE "survey_translations"."survey_id" = ? AND "survey_translations"."locale" = ?  ORDER BY "survey_translations"."id" ASC LIMIT 1  [["survey_id", 15], ["locale", "fr"]]
  CACHE (0.1ms)  SELECT  "survey_translations".* FROM "survey_translations" WHERE "survey_translations"."survey_id" = ? AND "survey_translations"."locale" = ?  ORDER BY "survey_translations"."id" ASC LIMIT 1  [["survey_id", 15], ["locale", "fr"]]
  Rendered partials/_answer.html.haml (83.7ms)
  CACHE (0.1ms)  SELECT  "survey_translations".* FROM "survey_translations" WHERE "survey_translations"."survey_id" = ? AND "survey_translations"."locale" = ?  ORDER BY "survey_translations"."id" ASC LIMIT 1  [["survey_id", 15], ["locale", "fr"]]
  CACHE (0.2ms)  SELECT  "survey_translations".* FROM "survey_translations" WHERE "survey_translations"."survey_id" = ? AND "survey_translations"."locale" = ?  ORDER BY "survey_translations"."id" ASC LIMIT 1  [["survey_id", 15], ["locale", "fr"]]
  Rendered partials/_answer.html.haml (46.4ms)
  CACHE (0.1ms)  SELECT  "survey_translations".* FROM "survey_translations" WHERE "survey_translations"."survey_id" = ? AND "survey_translations"."locale" = ?  ORDER BY "survey_translations"."id" ASC LIMIT 1  [["survey_id", 15], ["locale", "fr"]]
  CACHE (0.1ms)  SELECT  "survey_translations".* FROM "survey_translations" WHERE "survey_translations"."survey_id" = ? AND "survey_translations"."locale" = ?  ORDER BY "survey_translations"."id" ASC LIMIT 1  [["survey_id", 15], ["locale", "fr"]]
  Rendered partials/_answer.html.haml (43.6ms)
  CACHE (0.1ms)  SELECT  "survey_translations".* FROM "survey_translations" WHERE "survey_translations"."survey_id" = ? AND "survey_translations"."locale" = ?  ORDER BY "survey_translations"."id" ASC LIMIT 1  [["survey_id", 15], ["locale", "fr"]]
  CACHE (0.1ms)  SELECT  "survey_translations".* FROM "survey_translations" WHERE "survey_translations"."survey_id" = ? AND "survey_translations"."locale" = ?  ORDER BY "survey_translations"."id" ASC LIMIT 1  [["survey_id", 15], ["locale", "fr"]]
  Rendered partials/_answer.html.haml (43.3ms)
  CACHE (0.1ms)  SELECT  "survey_translations".* FROM "survey_translations" WHERE "survey_translations"."survey_id" = ? AND "survey_translations"."locale" = ?  ORDER BY "survey_translations"."id" ASC LIMIT 1  [["survey_id", 15], ["locale", "fr"]]
  CACHE (0.1ms)  SELECT  "survey_translations".* FROM "survey_translations" WHERE "survey_translations"."survey_id" = ? AND "survey_translations"."locale" = ?  ORDER BY "survey_translations"."id" ASC LIMIT 1  [["survey_id", 15], ["locale", "fr"]]
  Rendered partials/_answer.html.haml (39.9ms)
  Rendered partials/_question.html.haml (537.9ms)
  Rendered partials/_section.html.haml (563.5ms)

I checked the value of I18n.locale in _answer.html.haml and it was also fr. Pretty odd.

Any ideas what I could be doing wrong?

@prusswan
Copy link

It does not look like the translations were ever implemented in full. "survey_translations" only references survey_id and not any of the translatable models like Question or Answer with their own text fields, so it would not be very useful.

@yoon
Copy link
Member

yoon commented May 21, 2015

@archonic the UI (prompts, buttons, etc.) is localized separately from the text of the questions/answers themselves

@prusswan translations were implemented in full - they are simply linked through the survey, not via individual models

@prusswan
Copy link

@yoon Okay, I saw the yaml files, but initially I assumed they are just part of DSL, and not also used for retrieving the translations.

Edit:
It seems to be working on my end, the yaml content for the entire survey is stored in the SurveyTranslation model. One caveat however is that the questions and answers (or any other fields to be translated) must have reference identifiers, which cannot be just numbers, since they will just end up as numeric keys in hash returned from parsing the yaml content, and translates finds the translation by reference_identifier (which is a string key). This can be fixed by something like deep_stringify_keys, which is available in Rails 4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants