-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Make MacOS.language
less opinionated and add language
stanza.
#906
Conversation
👍 thanks! |
ae20770
to
6bf7b18
Compare
b21d419
to
1c748c6
Compare
Seems like the Mavericks |
@Homebrew/cask, could someone look over this? |
ef08490
to
fda249e
Compare
if args.include?(:default) | ||
# :default has to be the last language block in order to assign return value of the selected `language` block to `@language` | ||
@language = @language[:block].call | ||
end |
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 sure there is a better place/way to do this. Could need some help here, @jawshooah and @mwean.
@@ -41,8 +41,12 @@ def cat | |||
version.to_sym | |||
end | |||
|
|||
def languages | |||
@languages ||= Utils.popen_read("defaults", "read", ".GlobalPreferences", "AppleLanguages").delete(" \n\"()").split(",") |
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.
How about the following?
Utils.popen_read("defaults", "read", ".GlobalPreferences", "AppleLanguages").scan(/[^ \n"(),]+/)
beb8b3b
to
4fb377b
Compare
next unless l.match(string_or_regex) | ||
next unless @language[:level].nil? || @language[:level] > index | ||
@language = { | ||
block: block, |
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.
Up to you but I'd pull this back to being two-chars in from @language
.
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 is the style according to the current RuboCop config for Cask, so I'm leaving this as-is for now as it is used throughout cask/*
.
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.
🆒. Would be good after #989 to try and get a single style and rubocop
/brew style
invocation working for both so we can add brew style
to CI.
@@ -41,8 +41,12 @@ def cat | |||
version.to_sym | |||
end | |||
|
|||
def languages | |||
@languages ||= Utils.popen_read("defaults", "read", ".GlobalPreferences", "AppleLanguages").scan(/[^ \n"(),]+/) |
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 trying to work on this, but I'm having a ton of trouble getting things working. The |
Never used the |
5c9d8bc
to
1cd5384
Compare
def language | ||
@language ||= Utils.popen_read("defaults", "read", ".GlobalPreferences", "AppleLanguages").delete(" \n\"()").sub(/,.*/, "") | ||
languages.first |
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 will return nil
if there's no default language; previously it returned an empty string. I guess it doesn't matter in practice as there's a slim (or even zero?) chance of this macOS setting to be set to an empty array. Still wanted to point this out.
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.
there's a slim (or even zero?) chance of this macOS setting to be set to an empty array
There is only one way I can think of this could be the case: Manually changing/deleting .GlobalPreferences
, which is highly unlikely, so I think we're good here.
Would still like to get some feedback from @Homebrew/cask. |
MacOS.language
less opinionated.MacOS.language
less opinionated and add language
stanza.
I'd love to help, but I can't get things running locally. I'd also love to have some tests around this. I also don't like that we have to make |
Good point, this still needs tests.
This is not the case anymore. This is done using the |
e8daf87
to
deead34
Compare
8a954fd
to
e745adf
Compare
@reitermarkus I made a slightly different DSL: reitermarkus/brew@os-language...mwean:mw/language-dsl I wanted to avoid having a separate |
@mwean, I like the idea of only allowing strings in the DSL, so I have added a |
c9b1e30
to
077e8fc
Compare
I think this is pretty much ready. @mwean, I changed it mostly to your DSL, except for the |
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.
Just a couple of style nits, but all in all this LGTM 👍
|
||
@language_blocks.default = block | ||
else | ||
language_eval |
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.
You could clean this up a bit by making language_eval
return a value instead of having it set @language
. So here you'd have @language ||= language_eval
...
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'll leave this as is because of https://github.com/Homebrew/brew/pull/906/files/3def3b805b139960f11af68e07e3295c6dbe92cb#diff-f85d4948a976b9727959680dbfe1118aR16.
Otherwise I'd have to call @dsl.language
to actually “evaluate” the languages, which kind of defeats the purpose of having a language_eval
method.
end | ||
|
||
def language_eval | ||
return if instance_variable_defined?(:@language) |
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.
...and you could get rid of this early return...
strings.any? { |string| locale.include?(string) } | ||
} | ||
|
||
return @language = @language_blocks[key].call unless key.nil? |
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.
...and you could remove the @language =
here...
return @language = @language_blocks[key].call unless key.nil? | ||
} | ||
|
||
@language = @language_blocks.default.call |
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.
...and here.
|
||
return unless instance_variable_defined?(:@language_blocks) | ||
|
||
MacOS.languages.map(&Locale.method(:parse)).any? { |locale| |
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.
Seems like each
is a better fit here than any?
since you're not using the return value, as a boolean or otherwise.
3def3b8
to
e2b3753
Compare
brew tests
with your changes locally?This adds a
languages
method which returns an array, which in turn is called bylanguage
.A second addition is a
language
stanza to the cask DSL, which will hopefully make it easier to create and maintain multilingual casks.