ChristopherLucas / translateR

R Package for Cross-Language Topic Modeling
20 stars 17 forks source link

Update translate so that if source.lang is not provided for the Microsoft translation it has the API detect the language #15

Open kerry-ja opened 2 years ago

kerry-ja commented 2 years ago

I think a useful feature would be if the translate function was updated so that if source.lang is not provided for the Microsoft translation it has the API detect the language. This can be easily done in the Microsoft azure API by omitting the source language parameter.

I think this could be accomplished by updating the validateInput function so that the code to check for a valid language source code is updated to be: if (!(is.null(source.lang))) { if (!(source.lang %in% unname(unlist(languages["Microsoft"])))) { msg <- paste("The source.lang '", source.lang, "' is not a valid Microsoft language code. To see a list of Microsoft language codes, use getMicrosoftLanguages().", sep = "") stop(msg) } }

and the code for the microsoftTranslateToken function is updated so the code to assign the parameters is: if (missing(source.lang)) { params = paste("text=", URLencode(x), "&from=", source.lang, sep = "") } else { params = paste("text=", URLencode(x), "&to=", target.lang, "&from=", source.lang, sep = "") }