Skip to content

Commit

Permalink
attempt to fix encoding issues
Browse files Browse the repository at this point in the history
  • Loading branch information
seankross committed Mar 16, 2016
1 parent 2ad13dc commit 79faa3f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ Imports:
yaml,
RCurl,
digest,
tools
tools,
utils,
methods
Suggests:
stringi
Encoding: UTF-8
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ export(swirl_options)
export(uninstall_all_courses)
export(uninstall_course)
export(zip_course)
import(utils)
importFrom(RCurl,base64)
importFrom(RCurl,getForm)
importFrom(RCurl,postForm)
importFrom(digest,digest)
importFrom(httr,GET)
importFrom(httr,content)
importFrom(httr,progress)
importFrom(methods,is)
importFrom(stringr,fixed)
importFrom(stringr,str_c)
importFrom(stringr,str_detect)
Expand Down
2 changes: 1 addition & 1 deletion R/languages.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ compile_languages <- function(){

for(i in menus){
lang_name <- sub(".yaml$", "", basename(i))
cmd <- paste0(lang_name, " <- yaml.load_file('", i, "')")
cmd <- paste0(lang_name, " <- wrap_encoding(yaml.load_file('", i, "'))")
eval(parse(text=cmd))
}

Expand Down
2 changes: 1 addition & 1 deletion R/menu.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ welcome.default <- function(e, ...){
# @param e persistent environment used here only for its class attribute
#
housekeeping.default <- function(e){
swirl_out(paste0(s()%N%"Thanks, ", e$usr,s()%N%". Let's cover a few quick housekeeping items before we begin our first lesson. First of all, you should know that when you see '...', that means you should press Enter when you are done reading and ready to continue."))
swirl_out(paste0(s()%N%"Thanks, ", e$usr, s()%N%". Let's cover a couple of quick housekeeping items before we begin our first lesson. First of all, you should know that when you see '...', that means you should press Enter when you are done reading and ready to continue."))
readline(s()%N%"\n... <-- That's your cue to press Enter to continue")
swirl_out(s()%N%"Also, when you see 'ANSWER:', the R prompt (>), or when you are asked to select from a list, that means it's your turn to enter a response, then press Enter to continue.")
select.list(c(s()%N%"Continue.", s()%N%"Proceed.", s()%N%"Let's get going!"),
Expand Down
4 changes: 3 additions & 1 deletion R/swirl.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#' @importFrom stringr str_detect str_locate fixed str_split_fixed
#' @importFrom testthat expectation equals is_equivalent_to
#' @importFrom testthat is_identical_to is_a matches
#' @import utils
#' @importFrom methods is
#' @examples
#' \dontrun{
#'
Expand Down Expand Up @@ -375,7 +377,7 @@ resume.default <- function(e, ...){
temp <- mainMenu(e)
# If menu returns FALSE, the user wants to exit.
if(is.logical(temp) && !isTRUE(temp)){
swirl_out("Leaving swirl now. Type swirl() to resume.", skip_after=TRUE)
swirl_out(s()%N%"Leaving swirl now. Type swirl() to resume.", skip_after=TRUE)
esc_flag <- FALSE # To supress double notification
return(FALSE)
}
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
12 changes: 11 additions & 1 deletion tests/testthat/test-encoding.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,15 @@ test_that("Trying to parse the test-encoding.yaml", {
test_path <- system.file(file.path("test", "test-encoding.yaml"), package = "swirl")
suppressWarnings(result <- test_parse(test_path))
console <- capture.output(result)
expect_equal(stri_escape_unicode(strsplit(console[3], "\\s+")[[1]][3]), stri_escape_unicode("中文測試"))
test_phrase <- strsplit(console[3], "\\s+")[[1]][3]

if(.Platform$OS.type == "windows"){
expect_true(
identical(stri_escape_unicode(test_phrase), "<U+4E2D><U+6587><U+6E2C><U+8A66>") ||
identical(stri_escape_unicode(test_phrase), stri_escape_unicode("中文測試"))
)
} else {
expect_equal(stri_escape_unicode(test_phrase), stri_escape_unicode("中文測試"))

}
})

0 comments on commit 79faa3f

Please sign in to comment.