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

skip_if_localized() #565

Closed
krlmlr opened this Issue Jan 26, 2017 · 8 comments

Comments

Projects
None yet
3 participants
@krlmlr
Member

krlmlr commented Jan 26, 2017

to be able to skip tests that check the wording of an error message and fail in a non-English locale.

@hadley

This comment has been minimized.

Member

hadley commented Oct 1, 2017

Or we could add a language parameter to expect_error()? That's more likely to affect existing code, but it might be easy to discover.

@hadley

This comment has been minimized.

Member

hadley commented Oct 2, 2017

Hmmm, how do we know if you're localised?

@gaborcsardi

This comment has been minimized.

Member

gaborcsardi commented Oct 2, 2017

Maybe Sys.getenv("LANGUAGE") based on ?"environment variables"?

@gaborcsardi

This comment has been minimized.

@hadley

This comment has been minimized.

Member

hadley commented Oct 3, 2017

Something like

is_english <- function() {
  lang <- Sys.getenv("LANGUAGE")
  if (identical(lang, "en")) {
    return(TRUE)
  }
  
  if(.Platform$OS.type == "windows") {
    lc <- sub("\\..*", "", sub("_.*", "", Sys.getlocale("LC_CTYPE")))
    lc == "English" || lc == "C"
  } else {
    lc <- sub("\\..*", "", Sys.getlocale("LC_MESSAGES"))
    lc == "C" || substr(lc, 1, 2) == "en"
  }
}
@hadley

This comment has been minimized.

Member

hadley commented Oct 4, 2017

We need a different name because of localized vs localised. Maybe skip_if_not_en()?

@hadley

This comment has been minimized.

Member

hadley commented Oct 4, 2017

This feels awkward - I'd rather add a lang parameter to expect_error()

@hadley hadley closed this in 506f1a1 Oct 4, 2017

@hadley

This comment has been minimized.

Member

hadley commented Oct 9, 2017

Unfortunately it looks like that gettext caches translations between calls making it difficult to switch languages back and forth in a single session. I'll go back to skip_if_translated()

hadley added a commit that referenced this issue Oct 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment