Skip to content
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

Merged
merged 15 commits into from
Oct 3, 2016

Conversation

reitermarkus
Copy link
Member

@reitermarkus reitermarkus commented Sep 10, 2016

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew tests with your changes locally?

This adds a languages method which returns an array, which in turn is called by language.

A second addition is a language stanza to the cask DSL, which will hopefully make it easier to create and maintain multilingual casks.

@reitermarkus reitermarkus added the in progress Maintainers are working on this label Sep 10, 2016
@MikeMcQuaid
Copy link
Member

👍 thanks!

@reitermarkus
Copy link
Member Author

reitermarkus commented Sep 15, 2016

Seems like the Mavericks test-bot is using zh-Hans for some reason. So the regex in the tests should also match http://www.unicode.org/iso15924/iso15924-codes.html.

@reitermarkus
Copy link
Member Author

@Homebrew/cask, could someone look over this?

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
Copy link
Member Author

@reitermarkus reitermarkus Sep 17, 2016

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(",")
Copy link
Contributor

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"(),]+/)

@reitermarkus reitermarkus force-pushed the os-language branch 2 times, most recently from beb8b3b to 4fb377b Compare September 17, 2016 17:51
next unless l.match(string_or_regex)
next unless @language[:level].nil? || @language[:level] > index
@language = {
block: block,
Copy link
Member

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.

Copy link
Member Author

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/*.

Copy link
Member

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"(),]+/)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mwean
Copy link

mwean commented Sep 17, 2016

I'm trying to work on this, but I'm having a ton of trouble getting things working. The develop_brew_cask command isn't working, and I can't run the tests because of missing environment variables. I'm on Gitter if anyone can help me.

@reitermarkus
Copy link
Member Author

Never used the develop_brew_cask command, but this will probably need to be rewritten or be removed, as developing only Cask will not work as before anyways.

def language
@language ||= Utils.popen_read("defaults", "read", ".GlobalPreferences", "AppleLanguages").delete(" \n\"()").sub(/,.*/, "")
languages.first
Copy link
Contributor

@UniqMartin UniqMartin Sep 18, 2016

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.

Copy link
Member Author

@reitermarkus reitermarkus Sep 19, 2016

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.

@MikeMcQuaid
Copy link
Member

@reitermarkus 🚢?

@reitermarkus
Copy link
Member Author

Would still like to get some feedback from @Homebrew/cask.

@reitermarkus reitermarkus changed the title Make MacOS.language less opinionated. Make MacOS.language less opinionated and add language stanza. Sep 20, 2016
@mwean
Copy link

mwean commented Sep 20, 2016

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 :default the last declaration.

@reitermarkus
Copy link
Member Author

reitermarkus commented Sep 20, 2016

I'd also love to have some tests around this.

Good point, this still needs tests.

I also don't like that we have to make :default the last declaration.

This is not the case anymore. This is done using the language_eval method now.

@reitermarkus reitermarkus force-pushed the os-language branch 4 times, most recently from 8a954fd to e745adf Compare September 25, 2016 22:07
@mwean
Copy link

mwean commented Sep 26, 2016

@reitermarkus I made a slightly different DSL: reitermarkus/brew@os-language...mwean:mw/language-dsl I wanted to avoid having a separate default block, and I wanted to make it easy to make the language name different from the pattern.

@reitermarkus
Copy link
Member Author

@mwean, I like the idea of only allowing strings in the DSL, so I have added a Locale class to enable matching locales by string only instead of regexes and strings. Still needs to be integrated into the language DSL.

@reitermarkus reitermarkus force-pushed the os-language branch 2 times, most recently from c9b1e30 to 077e8fc Compare September 27, 2016 21:19
@reitermarkus
Copy link
Member Author

I think this is pretty much ready. @mwean, I changed it mostly to your DSL, except for the name: parameter, as I think simply using the return value of the block is more flexible, and more in line with url do. @jawshooah, please also have a final look.

Copy link
Contributor

@jawshooah jawshooah left a 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
Copy link
Contributor

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...

Copy link
Member Author

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)
Copy link
Contributor

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?
Copy link
Contributor

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
Copy link
Contributor

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|
Copy link
Contributor

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.

@reitermarkus reitermarkus merged commit 35ee283 into Homebrew:master Oct 3, 2016
@reitermarkus reitermarkus removed the in progress Maintainers are working on this label Oct 3, 2016
@reitermarkus reitermarkus deleted the os-language branch October 3, 2016 02:03
@Homebrew Homebrew locked and limited conversation to collaborators May 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants