Skip to content

Commit 71b7f86

Browse files
committed
Use global locale for starter projects
There's currently a caching issue when switching between locales on the project site [1]. To fix this we can only load the project if it has the expected locale. However, this would break caching for projects that aren't localized. The code editor only uses the project cache when you've not yet logged in or saved a project. The projects you're likely to be editing in this case are the blank starter projects. Since these projects are blank with no instructions they aren't really localizable so I have decided to flag them as having a 'global' localization. Adding this to the list of locales will mean we can also set this on any imported projects we want this behaviour for. I'll amend [1] to allow using the cache when when the project is set to global. ### After deploy Deploy separate migration to update locale for the two blank projects. [1] RaspberryPiFoundation/editor-ui#1342
1 parent 11b4fce commit 71b7f86

5 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/locales.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def load_locales
1818
pt-PT ro-RO ru-RU sh-ZW si-LK sk-SK sl-SI so-SO sq-AL sr-SP sv-SE sw-KE ta-IN te-IN th-TH tr-TR tt-RU uk-UA ur-PK vi-VN vls-BE xh-ZA zh-CN zh-TW
1919
]
2020
I18n.default_locale = :en
21-
I18n.available_locales = two_letter_locales + four_letter_locales
21+
I18n.available_locales = two_letter_locales + four_letter_locales + [:global]
2222
end
2323
end
2424
end

lib/project_loader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class ProjectLoader
55

66
def initialize(identifier, locales)
77
@identifier = identifier
8-
@locales = [*locales, 'en', nil]
8+
@locales = [*locales, 'global', 'en', nil]
99
end
1010

1111
def load(include_images: false)

lib/tasks/project_components/blank_html_starter/project_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
NAME: 'Blank HTML & CSS Starter'
22
IDENTIFIER: 'blank-html-starter'
33
TYPE: 'html'
4+
LOCALE: 'global'
45
COMPONENTS:
56
- name: 'index'
67
extension: 'html'

lib/tasks/project_components/blank_python_starter/project_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
NAME: 'Blank Python Starter'
22
IDENTIFIER: 'blank-python-starter'
33
TYPE: 'python'
4+
LOCALE: 'global'
45
COMPONENTS:
56
- name: 'main'
67
extension: 'py'

spec/lib/project_loader_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
end
4242
end
4343

44+
context 'when global project with identifier exists' do
45+
let!(:global_project) { create(:project, identifier:, locale: 'global') }
46+
47+
it 'defaults to global' do
48+
expect(loaded_project).to eq(global_project)
49+
end
50+
end
51+
4452
context 'when no preferred locale or English versions but user version exists' do
4553
let!(:user_project) { create(:project, identifier:, locale: nil) }
4654

0 commit comments

Comments
 (0)