File tree 3 files changed +6
-20
lines changed 3 files changed +6
-20
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ class PagePreviewController < ApplicationController
7
7
include Maglev ::ContentLocaleConcern
8
8
9
9
before_action :fetch_maglev_site
10
- before_action :extract_content_locale
10
+ around_action :extract_content_locale
11
11
12
12
def index
13
13
render_maglev_page
@@ -43,9 +43,9 @@ def use_engine_vite?
43
43
false
44
44
end
45
45
46
- def extract_content_locale
46
+ def extract_content_locale ( & block )
47
47
_ , locale = maglev_services . extract_locale . call ( params : params , locales : maglev_site . locale_prefixes )
48
- ::I18n . locale = locale
48
+ ::I18n . with_locale ( locale , & block )
49
49
end
50
50
51
51
def fallback_to_default_locale
Original file line number Diff line number Diff line change @@ -4,24 +4,9 @@ import messages from '@/locales'
4
4
5
5
Vue . use ( VueI18n )
6
6
7
- const AVAILABLE_LOCALES = [ 'en' , 'fr' ]
8
- var locale = 'en'
9
-
10
- if ( document . documentElement . lang ) {
11
- // fetch the local from the HTML tag
12
- locale = document . documentElement . lang
13
- } else {
14
- // try to fetch the browser locale
15
- const language = navigator . languages [ 0 ]
16
- if ( language ) {
17
- locale = language . split ( '-' ) [ 0 ]
18
- if ( AVAILABLE_LOCALES . indexOf ( locale ) === - 1 ) locale = null
19
- }
20
- }
21
-
22
7
const i18n = new VueI18n ( {
23
- locale,
24
- fallbackLocale : AVAILABLE_LOCALES [ 0 ] ,
8
+ locale : window . uiLocale ,
9
+ fallbackLocale : 'en' ,
25
10
messages,
26
11
} )
27
12
Original file line number Diff line number Diff line change 8
8
9
9
<%= javascript_tag nonce : true do %>
10
10
window.locale = <%= h content_locale . to_json . html_safe %> ;
11
+ window.uiLocale = <%= h editor_ui_locale . to_json . html_safe %> ;
11
12
window.baseUrl = <%= h site_base_editor_path . to_json . html_safe %> ;
12
13
window.leaveUrl = <%= site_leave_editor_path . to_json . html_safe %> ;
13
14
window.apiBaseUrl = <%= h api_base_path . to_json . html_safe %> ;
You can’t perform that action at this time.
0 commit comments