Commit b081e678 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '349502-make-navigation-themes-translatable' into 'master'

Make navigation themes translatable

See merge request gitlab-org/gitlab!77483
parents 373086d4 df415198
......@@ -4,8 +4,8 @@
module PreferencesHelper
def layout_choices
[
['Fixed', :fixed],
['Fluid', :fluid]
[s_('Layout|Fixed'), :fixed],
[s_('Layout|Fluid'), :fluid]
]
end
......@@ -40,9 +40,9 @@ module PreferencesHelper
def project_view_choices
[
['Files and Readme (default)', :files],
['Activity', :activity],
['Readme', :readme]
[s_('ProjectView|Files and Readme (default)'), :files],
[s_('ProjectView|Activity'), :activity],
[s_('ProjectView|Readme'), :readme]
]
end
......
......@@ -2,7 +2,7 @@
- @content_class = "limit-container-width" unless fluid_layout
- user_theme_id = Gitlab::Themes.for_user(@user).id
- user_fields = { theme: user_theme_id, gitpod_enabled: @user.gitpod_enabled, sourcegraph_enabled: @user.sourcegraph_enabled }.to_json
- @themes = Gitlab::Themes::THEMES.to_json
- @themes = Gitlab::Themes::available_themes.to_json
- data_attributes = { themes: @themes, integration_views: integration_views.to_json, user_fields: user_fields, body_classes: Gitlab::Themes.body_classes, profile_preferences_path: profile_preferences_path }
- Gitlab::Themes.each do |theme|
......
......@@ -7,21 +7,23 @@ module Gitlab
# Struct class representing a single Scheme
Scheme = Struct.new(:id, :name, :css_class)
SCHEMES = [
Scheme.new(1, 'White', 'white'),
Scheme.new(2, 'Dark', 'dark'),
Scheme.new(3, 'Solarized Light', 'solarized-light'),
Scheme.new(4, 'Solarized Dark', 'solarized-dark'),
Scheme.new(5, 'Monokai', 'monokai'),
Scheme.new(6, 'None', 'none')
].freeze
def self.available_schemes
[
Scheme.new(1, s_('SynthaxHighlightingTheme|Light'), 'white'),
Scheme.new(2, s_('SynthaxHighlightingTheme|Dark'), 'dark'),
Scheme.new(3, s_('SynthaxHighlightingTheme|Solarized Light'), 'solarized-light'),
Scheme.new(4, s_('SynthaxHighlightingTheme|Solarized Dark'), 'solarized-dark'),
Scheme.new(5, s_('SynthaxHighlightingTheme|Monokai'), 'monokai'),
Scheme.new(6, s_('SynthaxHighlightingTheme|None'), 'none')
]
end
# Convenience method to get a space-separated String of all the color scheme
# classes that might be applied to a code block.
#
# Returns a String
def self.body_classes
SCHEMES.collect(&:css_class).uniq.join(' ')
available_schemes.collect(&:css_class).uniq.join(' ')
end
# Get a Scheme by its ID
......@@ -32,12 +34,12 @@ module Gitlab
#
# Returns a Scheme
def self.by_id(id)
SCHEMES.detect { |s| s.id == id } || default
available_schemes.detect { |s| s.id == id } || default
end
# Returns the number of defined Schemes
def self.count
SCHEMES.size
available_schemes.size
end
# Get the default Scheme
......@@ -51,7 +53,7 @@ module Gitlab
#
# Yields the Scheme object
def self.each(&block)
SCHEMES.each(&block)
available_schemes.each(&block)
end
# Get the Scheme for the specified user, or the default
......@@ -68,7 +70,7 @@ module Gitlab
end
def self.valid_ids
SCHEMES.map(&:id)
available_schemes.map(&:id)
end
end
end
......@@ -13,26 +13,28 @@ module Gitlab
Theme = Struct.new(:id, :name, :css_class, :css_filename, :primary_color)
# All available Themes
THEMES = [
Theme.new(1, 'Indigo', 'ui-indigo', 'theme_indigo', '#292961'),
Theme.new(6, 'Light Indigo', 'ui-light-indigo', 'theme_light_indigo', '#4b4ba3'),
Theme.new(4, 'Blue', 'ui-blue', 'theme_blue', '#1a3652'),
Theme.new(7, 'Light Blue', 'ui-light-blue', 'theme_light_blue', '#2261a1'),
Theme.new(5, 'Green', 'ui-green', 'theme_green', '#0d4524'),
Theme.new(8, 'Light Green', 'ui-light-green', 'theme_light_green', '#156b39'),
Theme.new(9, 'Red', 'ui-red', 'theme_red', '#691a16'),
Theme.new(10, 'Light Red', 'ui-light-red', 'theme_light_red', '#a62e21'),
Theme.new(2, 'Dark', 'ui-dark', 'theme_dark', '#303030'),
Theme.new(3, 'Light', 'ui-light', 'theme_light', '#666'),
Theme.new(11, 'Dark Mode (alpha)', 'gl-dark', nil, '#303030')
].freeze
def available_themes
[
Theme.new(1, s_('NavigationTheme|Indigo'), 'ui-indigo', 'theme_indigo', '#292961'),
Theme.new(6, s_('NavigationTheme|Light Indigo'), 'ui-light-indigo', 'theme_light_indigo', '#4b4ba3'),
Theme.new(4, s_('NavigationTheme|Blue'), 'ui-blue', 'theme_blue', '#1a3652'),
Theme.new(7, s_('NavigationTheme|Light Blue'), 'ui-light-blue', 'theme_light_blue', '#2261a1'),
Theme.new(5, s_('NavigationTheme|Green'), 'ui-green', 'theme_green', '#0d4524'),
Theme.new(8, s_('NavigationTheme|Light Green'), 'ui-light-green', 'theme_light_green', '#156b39'),
Theme.new(9, s_('NavigationTheme|Red'), 'ui-red', 'theme_red', '#691a16'),
Theme.new(10, s_('NavigationTheme|Light Red'), 'ui-light-red', 'theme_light_red', '#a62e21'),
Theme.new(2, s_('NavigationTheme|Dark'), 'ui-dark', 'theme_dark', '#303030'),
Theme.new(3, s_('NavigationTheme|Light'), 'ui-light', 'theme_light', '#666'),
Theme.new(11, s_('NavigationTheme|Dark Mode (alpha)'), 'gl-dark', nil, '#303030')
]
end
# Convenience method to get a space-separated String of all the theme
# classes that might be applied to the `body` element
#
# Returns a String
def body_classes
THEMES.collect(&:css_class).uniq.join(' ')
available_themes.collect(&:css_class).uniq.join(' ')
end
# Get a Theme by its ID
......@@ -43,12 +45,12 @@ module Gitlab
#
# Returns a Theme
def by_id(id)
THEMES.detect { |t| t.id == id } || default
available_themes.detect { |t| t.id == id } || default
end
# Returns the number of defined Themes
def count
THEMES.size
available_themes.size
end
# Get the default Theme
......@@ -62,7 +64,7 @@ module Gitlab
#
# Yields the Theme object
def each(&block)
THEMES.each(&block)
available_themes.each(&block)
end
# Get the Theme for the specified user, or the default
......@@ -79,7 +81,7 @@ module Gitlab
end
def self.valid_ids
THEMES.map(&:id)
available_themes.map(&:id)
end
private
......@@ -87,7 +89,7 @@ module Gitlab
def default_id
@default_id ||= begin
id = Gitlab.config.gitlab.default_theme.to_i
theme_ids = THEMES.map(&:id)
theme_ids = available_themes.map(&:id)
theme_ids.include?(id) ? id : APPLICATION_DEFAULT
end
......
......@@ -20827,6 +20827,12 @@ msgstr ""
msgid "Launch a ready-to-code development environment for your project."
msgstr ""
msgid "Layout|Fixed"
msgstr ""
msgid "Layout|Fluid"
msgstr ""
msgid "Lead Time"
msgstr ""
......@@ -23274,6 +23280,39 @@ msgstr ""
msgid "Navigation bar"
msgstr ""
msgid "NavigationTheme|Blue"
msgstr ""
msgid "NavigationTheme|Dark"
msgstr ""
msgid "NavigationTheme|Dark Mode (alpha)"
msgstr ""
msgid "NavigationTheme|Green"
msgstr ""
msgid "NavigationTheme|Indigo"
msgstr ""
msgid "NavigationTheme|Light"
msgstr ""
msgid "NavigationTheme|Light Blue"
msgstr ""
msgid "NavigationTheme|Light Green"
msgstr ""
msgid "NavigationTheme|Light Indigo"
msgstr ""
msgid "NavigationTheme|Light Red"
msgstr ""
msgid "NavigationTheme|Red"
msgstr ""
msgid "Nav|Help"
msgstr ""
......@@ -28117,6 +28156,15 @@ msgstr ""
msgid "ProjectTemplates|iOS (Swift)"
msgstr ""
msgid "ProjectView|Activity"
msgstr ""
msgid "ProjectView|Files and Readme (default)"
msgstr ""
msgid "ProjectView|Readme"
msgstr ""
msgid "Projects"
msgstr ""
......@@ -34495,6 +34543,24 @@ msgstr ""
msgid "Syntax is incorrect."
msgstr ""
msgid "SynthaxHighlightingTheme|Dark"
msgstr ""
msgid "SynthaxHighlightingTheme|Light"
msgstr ""
msgid "SynthaxHighlightingTheme|Monokai"
msgstr ""
msgid "SynthaxHighlightingTheme|None"
msgstr ""
msgid "SynthaxHighlightingTheme|Solarized Dark"
msgstr ""
msgid "SynthaxHighlightingTheme|Solarized Light"
msgstr ""
msgid "System"
msgstr ""
......
......@@ -15,7 +15,7 @@ RSpec.describe Gitlab::ColorSchemes do
describe '.by_id' do
it 'returns a scheme by its ID' do
expect(described_class.by_id(1).name).to eq 'White'
expect(described_class.by_id(1).name).to eq 'Light'
expect(described_class.by_id(4).name).to eq 'Solarized Dark'
end
end
......
......@@ -28,7 +28,7 @@ RSpec.describe Gitlab::Themes, lib: true do
it 'prevents an infinite loop when configuration default is invalid' do
default = described_class::APPLICATION_DEFAULT
themes = described_class::THEMES
themes = described_class.available_themes
config = double(default_theme: 0).as_null_object
allow(Gitlab).to receive(:config).and_return(config)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment