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
Only update dsls.en.yml for levels we want to translate #27881
Conversation
Hamms
commented
Apr 4, 2019
•
edited
edited
- Make it possible to render DSL levels without translations #27953 added the ability for DSL levels to still render even if their relevant data isn't in the translation system (ie, the dsls.en.yml file)
- 02506f6 stops regenerating dsls.en.yml as part of the build process (since we now no longer rely on that file as the exclusive source of truth)
- b96e61e updates the levelbuilder "level save" operation to only add content to the dsls.en.yml file on save if it's in the subset of levels we know we want to translate
Right now, all DSL levels depend on I18n.t to render their content, and will fall back to `nil` if they can't find the translation. We want to be able to only sync data into the translation system if we want to actually translate it, so we add the ability for DSL levels to fall back to the database content if they can't find translation data.
Repeat of #24384 This broke things the first time because we depended on content being in the dsls.en.yml file in order to render successfully; we no longer do, so it should be safe to stop this.
First attempted in #24183 This broke all untranslated DSL levels at the time, because we were still depending on the i18n file for content. Now that we can safely fall back to databse data if i18n data is missing, we can try this again.
@@ -646,4 +646,90 @@ def stub_country(code) | |||
assert_equal new_toolbox, options[:level]["toolbox"] | |||
assert_equal new_start, options[:level]["startBlocks"] | |||
end | |||
|
|||
test 'string_or_image can retrieve plain text' do | |||
assert_equal string_or_image('match', "test"), "test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that this is the only one of the added tests that is actually testing new functionality; all the others are testing existing functionality
What will be the new "source of truth" for non-i18n levels? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good! I have a couple of questions, mostly for my own education. :)
@@ -654,7 +654,7 @@ def string_or_image(prefix, text, source_level = nil) | |||
) | |||
else | |||
level_name = source_level ? source_level.name : @level.name | |||
data_t(prefix + '.' + level_name, text) | |||
data_t(prefix + '.' + level_name, text, text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We pass text as both the key and the default because the key is the English text right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!
That means that this PR doesn't address the issue of overly long keys, nor does it make it any easier to change the way we store the data in a way that would help us address that issue
@@ -59,7 +59,7 @@ class DslTest < ActiveSupport::TestCase | |||
test 'should encrypt when saving in levelbuilder and decrypt when parsing from file' do | |||
# don't actually write a file, but check that we are writing the encrypted version | |||
Rails.application.config.stubs(:levelbuilder_mode).returns true | |||
File.expects(:write).twice.with do |pathname, contents| | |||
File.expects(:write).once.with do |pathname, contents| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test level isn't in a script we're trying to internationalize, so we no longer expect it to update the i18n file on save (only its actual level file)
The database/their individual level files in |
@@ -74,7 +75,7 @@ def self.create_from_level_builder(params, level_params, old_name = nil) | |||
# Save updated level data to external files | |||
if Rails.application.config.levelbuilder_mode | |||
level.rewrite_dsl_file(text) | |||
rewrite_i18n_file(i18n) | |||
rewrite_i18n_file(i18n) if level.script_levels.any? {|sl| ScriptConstants.i18n? sl.script.name} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the long-term plan to delete dsls.en.yml entirely and generate it during the sync-codeorg-in
step? Or keep it for translated script levels only?
Commit 3d8eb04 seems like a clear step forward, and maybe is worth merging on its own...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually not sure!
I played around with the idea of deleting it entirely and just generating it during the sync-codeorg-in step, but ran into a couple challenges there. Specifically, that step is built entirely around the idea of being able to get all the data it needs directly from the files in the filesystem, without the need for syncing everything into a database and using ActiveRecord. Unfortunately, it turns out it's a lot more complicated than I thought it would be to get all the dsls data from the filesystem. (see #24369 (comment) for more info)
So I decided to just keep it around for the translated script in #27885; the idea there is that this file would get updated when the levels get changed in levelbuilder (and only get updated there, rather than as a part of any build process) and then consumed by the i18n sync (and only get consumed there, rather than as a part of any build process).
Unfortunately, that approach doesn't work very well for contained levels, since it's harder for them to know whether they're in a script or not. My short-term plan at this point is just to get things working with the "keep a minimal version of dsls.en.yml around", but I don't yet know whether or not that's the long-term solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to get @islemaster's input here from the Learning Platform perspective:
- Are "contained" levels something we plan to fully-support or deprecate going forward?
- How are these levels being found during the yearly course version clone process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @davidsbailey knows more about this than I do, but contained levels (a.k.a. prediction levels?) are used extensively in our system - I see more than 200, spread out across courses A, B, C, D, E, F, CSD, and Dance Party. If we're planning to deprecate them for some other representation, we've got a migration ahead of us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are "contained" levels something we plan to fully-support or deprecate going forward?
yes, contained levels (a.k.a. prediction levels) are something we plan to fully support moving forward.
if some linkage could be added in the rails models so that a contained level knew what level it was contained in, would that make this problem any easier to tackle?