File tree Expand file tree Collapse file tree 2 files changed +52
-3
lines changed Expand file tree Collapse file tree 2 files changed +52
-3
lines changed Original file line number Diff line number Diff line change @@ -63,10 +63,23 @@ def self.wsl_version
63
63
def self . languages
64
64
return @languages if @languages . present?
65
65
66
- os_langs = Utils . popen_read ( "localectl" , "list-locales" )
67
- os_langs = os_langs . scan ( /[^ \n "(),]+/ ) . map { |item | item . split ( "." ) . first . tr ( "_" , "-" ) }
66
+ locale_variables = ENV . keys . grep ( /^(?:LC_\S +|LANG|LANGUAGE)\Z / ) . sort
67
+ ctl_ret = Utils . popen_read ( "localectl" , "list-locales" )
68
+ if ctl_ret . present?
69
+ list = ctl_ret . scan ( /[^ \n "(),]+/ )
70
+ elsif locale_variables . present?
71
+ keys = locale_variables . select { |var | ENV . fetch ( var ) }
72
+ list = keys . map { |key | ENV . fetch ( key ) }
73
+ else
74
+ list = [ "en_US.utf8" ]
75
+ end
76
+
77
+ @languages = list . map { |item | item . split ( "." ) . first . tr ( "_" , "-" ) }
78
+ end
68
79
69
- @languages = os_langs
80
+ sig { returns ( T . nilable ( String ) ) }
81
+ def self . language
82
+ languages . first
70
83
end
71
84
end
72
85
end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "locale"
4
+ require "os/linux"
5
+
6
+ RSpec . describe OS ::Linux do
7
+ describe "::languages" , :needs_linux do
8
+ it "returns a list of all languages" do
9
+ expect ( described_class . languages ) . not_to be_empty
10
+ end
11
+ end
12
+
13
+ describe "::language" , :needs_linux do
14
+ it "returns the first item from #languages" do
15
+ expect ( described_class . language ) . to eq ( described_class . languages . first )
16
+ end
17
+ end
18
+
19
+ describe "::'os_version'" , :needs_linux do
20
+ it "returns the OS version" do
21
+ expect ( described_class . os_version ) . not_to be_empty
22
+ end
23
+ end
24
+
25
+ describe "::'wsl?'" do
26
+ it "returns the WSL state" do
27
+ expect ( described_class . wsl? ) . to be ( false )
28
+ end
29
+ end
30
+
31
+ describe "::'wsl_version'" , :needs_linux do
32
+ it "returns the WSL version" do
33
+ expect ( described_class . wsl_version ) . to match ( Version ::NULL )
34
+ end
35
+ end
36
+ end
You can’t perform that action at this time.
0 commit comments