pbs-assess / rosettafish

:fishing_pole_and_fish: An R package for translating fish- and fisheries-related terms
4 stars 15 forks source link

rosettafish

R-CMD-check Coverage
status

rosettafish is an R package to translate fish- and fisheries-related words or short phrases between languages (English to French or French to English).

This would apply to figure labels to produce separate figures in two languages, or a single figure with labels in two languages. It can also be used for other text (such as table headings), but is not intended for translation of complete sentences.

In particular, it should be useful for automatically producing translated technical figures to go into Research Documents and presentations. This is done when building the figures (in R) and saves someone having to manually edit the figure (in, say, Photoshop). This preserves the quality and the output formats of figures in both languages, and is especially time-saving when the same figure axes are used for multiple figures (e.g., a time series of biomass estimates for multiple model runs of a stock assessment).

The package has a built-in .csv file of English-French translations of common technical fisheries terms (that are often incorrectly translated by generic automatic translators). Users can add to this or use their own file, and are encouraged to add to the ever-expanding list of common terms using the instructions below.

Installation

You can install rosettafish with:

# install.packages("devtools")
devtools::install_github("pbs-assess/rosettafish")

Examples

library(rosettafish)
library(ggplot2)
set.seed(1)
years <- seq(1980, 2018)
df <- data.frame(years, biomass = 2000 * rlnorm(length(years), 0, 1))
make_plot <- function(french = FALSE) {
  ggplot(df, aes(years, biomass)) + geom_line() +
    xlab(en2fr("Year", french)) +
    ylab(en2fr("Biomass", french))
}
make_plot()
make_plot(french = TRUE)
english <- TRUE
ggplot(df, aes(years, biomass)) + geom_line() +
  xlab(fr2en("Année", english)) +
  ylab(fr2en("Biomasse", english))
ggplot(df, aes(years, biomass)) + geom_line() +
  xlab(trans("Year", from = "english", to = c("english", "french"))) +
  ylab(trans("Biomass", from = "english", to = c("english", "french")))

Updating the list of translated scientific terms

If you’re comfortable with Git and file encodings:

  1. Fork and clone this repository.
  2. Add the terms to the end of the file data-raw/terms.csv with a text editor (not Excel!). Ensure your editor is saving in UTF-8 format or the French accents will be destroyed. Help with UTF-8 file encoding and RStudio.
  3. Source the file data/make-dictionary.R to include data in the package (see the more detailed instructions in the next section).
  4. Push to GitHub and submit a pull request.

If you’d rather a quick way to edit without worrying about Git or file encodings:

  1. Edit the file directly on GitHub.
  2. Add the terms to the end of the file.
  3. Click the button to create a pull request.

If both of those options are confusing, just create an Issue on the GitHub site and give us your new translated terms.

Updating the list and reloading the package to use your terms

The above instructions are fine if you’re willing to wait for us to merge your pull request. If instead you want to update the terms and use the package immediately, follow the above instructions to add your terms and then open data-raw/make-dictionary.R and source it in R. This will:

After sourcing this file, you can reinstall the package to use it. For example, with your working directory set to the rosettafish folder:

devtools::install(quick = TRUE, dependencies = FALSE)

Or open the project in RStudio and run Build > Install and Restart.

You will need to restart any other R sessions to be able to use the newly installed package.

Code of conduct

Please note that the ‘rosettafish’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.