Skip to content

Commit

Permalink
Merge pull request #100 from r-devel/main
Browse files Browse the repository at this point in the history
update branch
  • Loading branch information
SaranjeetKaur authored Oct 21, 2022
2 parents e18b391 + 0564fd3 commit 22a7398
Show file tree
Hide file tree
Showing 22 changed files with 345 additions and 45 deletions.
51 changes: 45 additions & 6 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
"question",
"eventOrganizing",
"talk",
"video"
"video",
"review",
"example",
"research"
]
},
{
Expand All @@ -63,7 +66,12 @@
"avatar_url": "https://avatars.githubusercontent.com/u/6818218?v=4",
"profile": "http://llrs.dev",
"contributions": [
"review"
"review",
"content",
"question",
"research",
"doc",
"example"
]
},
{
Expand All @@ -73,7 +81,9 @@
"profile": "http://tdhock.github.io",
"contributions": [
"review",
"example"
"example",
"research",
"question"
]
},
{
Expand All @@ -82,7 +92,9 @@
"avatar_url": "https://avatars.githubusercontent.com/u/3341603?v=4",
"profile": "https://github.com/bettinagruen",
"contributions": [
"review"
"review",
"research",
"question"
]
},
{
Expand Down Expand Up @@ -119,7 +131,10 @@
"profile": "https://github.com/MichaelChirico",
"contributions": [
"review",
"question"
"question",
"content",
"doc",
"research"
]
},
{
Expand Down Expand Up @@ -178,12 +193,36 @@
"contributions": [
"review"
]
},
{
"login": "nbenn",
"name": "nbenn",
"avatar_url": "https://avatars.githubusercontent.com/u/3158446?v=4",
"profile": "https://github.com/nbenn",
"contributions": [
"review",
"research",
"question"
]
},
{
"login": "benubah",
"name": "Ben",
"avatar_url": "https://avatars.githubusercontent.com/u/11357251?v=4",
"profile": "https://github.com/benubah",
"contributions": [
"content",
"review",
"research",
"question"
]
}
],
"contributorsPerLine": 7,
"projectName": "rdevguide",
"projectOwner": "r-devel",
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true
"skipCi": true,
"commitConvention": "angular"
}
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Custom issue template
about: Describe this issue template's purpose here.
title: ''
labels: ''
assignees: ''

---


20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
17 changes: 11 additions & 6 deletions .github/workflows/deploy_bookdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ jobs:
name: Render-Book
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-pandoc@v1
- uses: actions/checkout@v3
- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-tinytex@v2
- name: Install rmarkdown
run: Rscript -e 'install.packages(c("rmarkdown","bookdown"))'
- name: Render Book
run: Rscript -e 'bookdown::render_book("index.Rmd")'
- uses: actions/upload-artifact@v1
- name: Render HTML
run: Rscript -e 'bookdown::render_book("index.Rmd", "bookdown::gitbook")'
- name: Render PDF
run: Rscript -e 'bookdown::render_book("index.Rmd", "bookdown::pdf_book")'
- name: Render ePub
run: Rscript -e 'bookdown::render_book("index.Rmd", "bookdown::epub_book")'
- uses: actions/upload-artifact@v3
with:
name: docs
path: docs/
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
.DS_Store
docs/
rdevguide.rds

# temp files
*~
2 changes: 1 addition & 1 deletion 01-Introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This guide is heavily influenced by the [Python Developer Guide](https://devguid

This guide is built using bookdown which makes editing it easier, provided you have a GitHub account (sign-up at [github.com](https://github.com/)). After you log-in to GitHub, click on the ‘Edit’ icon highlighted with a red ellipse in the image below. This will take you to an editable version of the the source R Markdown file that generated the page you are on:

![](https://user-images.githubusercontent.com/28556616/122679827-03314a80-d20a-11eb-9714-06ae588127f0.png)
![Screenshot of the toolbar in the HTML version of the guide, with the Edit button (pencil and paper icon) circled in red.](img/edit_icon.png)

Use the [issue tracker](https://github.com/forwards/rdevguide/issues) to raise an issue about the guide’s content or to make a feature request.

Expand Down
2 changes: 1 addition & 1 deletion 04-reviewing_bugs_in_R.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ If you would like to see how bugs are reviewed on Bugzilla, [here](https://bugs.

**Note**:

There is a `#bugreports-for-review` channel on the [R Contributors slack](https://r-contributors.slack.com/) where you can share your bug report(s) for review/feedback before submitting to Bugzilla. This can help with checking that it really is a bug, that you have included the important information and excluded redundant information.
There is a `#bug-reporting` channel on the [R Contributors slack](https://r-contributors.slack.com/) where you can share your bug report(s) for review/feedback before submitting to Bugzilla. This can help with checking that it really is a bug, that you have included the important information and excluded redundant information.

## See also

Expand Down
2 changes: 1 addition & 1 deletion 07-documenting_R.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The language used in the documentations should follow these basic rules:

3. Short code examples can help in understanding better. Readers can often grasp a simple example more quickly than they can digest a formal description. Usually people learn faster with concrete, motivating examples that match the context of a typical use case.

4. Giving a code equivalent (or approximate equivalent) can be a useful in addition to the description provided. You should carefully weigh whether the code equivalent adds value to the document.
4. Giving a code equivalent (or approximate equivalent) can be a useful addition to the description provided. You should carefully weigh whether the code equivalent adds value to the document.

5. The tone of the documentation needs to be respectful of the reader’s background. Lay out the relevant information, show motivating use cases, and do your best to connect-the-dots. The documentation is meant for newcomers, many of whom will be using it to evaluate the R language as a whole. The experience needs to be positive and not leave the reader with worries that something bad will happen if they make a mistake.

Expand Down
159 changes: 159 additions & 0 deletions 08-translations.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Translations

This chapter covers internationalization in R, i.e., the display of messages in languages other than English. All
output in R (such as messages emitted by `stop()`, `warning()`, or `message()`) is eligible for translation, as
are menu labels in the GUI. Depending on the version of R that you are using, some of the languages might already
be available while others may need work. R leverages the [`gettext`](https://www.gnu.org/software/gettext/) program
to handle the conversion from English to arbitrary target languages.

Having messages available in other languages can be an important bridge for R learners not confident in English --
rather than learning two things at once (coding in R and processing diagnostic information in English), they can
focus on coding while getting more natural errors/warnings in their native tongue.

The [`gettext` manual](https://www.gnu.org/software/gettext/manual/index.html) is a more canonical reference for a
deep understanding of how `gettext` works. This chapter will just give a broad overview, with particular focus on
how things work for R, with the goal of making it as low-friction as possible for developers and users to contribute
new/updated translations.

## How translations work

Each of the default packages distributed with R (i.e., those found in `./src/library` such as `base`, `utils`,
and `stats` and which have priority base) contains a `po` directory that is the central location for cataloguing/translating each package's
messages.

### `.pot` files

The `.pot` file is a snapshot of the messages available in a given **domain**. A domain in R typically identifies
a source package and a source language (either R or C/C++). For example, the file `R-stats.pot`
(found in the R sources in `./src/library/stats/po`) is a catalogue of all messages produced by R code in the
`base` package, while `stats.pot` is a catalogue of all messages produced by C code in the `stats` package.

There are two exceptions to the basic pattern described above. The first is the domain for messages produced by
the C code which is the fundamental backing of R itself (especially, but not exclusively, the C code under
./src/main). The associated `.pot` file is `R.pot` and it is found in `./src/library/base/po`. `R-base.pot` is a
normal `.pot` file because base has a normal `R` directory.

The second is the domain for the Windows R GUI, i.e., the text in the menus and elsewhere in the R GUI program
available for running R on Windows. These messages are stored in the `RGui.pot` domain, also in the `po`
directory for `base`, and are most commonly derived from C code found in `./src/gnuwin32`. One reason to keep
this domain separate is that it is only relevant to one platform (Windows). In particular, Windows has historically
different character encodings, so that it made more sense for Windows developers to produce translations specifically for Windows, since it is non-trivial for non-Windows users to test their translations for the Windows GUI.

#### Generating `.pot` files

For outside contributors, there's no need to update .pot files -- translators will typically take the R `.pot` files
as given and generate `.po` files. These will be sent along to a language-specific translation maintainer, who then
compiles them to send to the R Core developer responsible for translations, who finally applies them as a patch.

To emphasize, this section is almost always not needed for contributing translations -- it is here for
completeness and edification.

### `.po` files

.po files are the most important artifacts for translators. They provide the (human-readable!) mapping between
the messages as they appear in the source code and how the messages will appear to users in translated locales.

#### Singular messages

Most messages appear as `msgid`/`msgstr` pairs. The former gives the message as it appears in the code, while the
latter shows how it should appear in translation. For example, here is an error in German (locale: `de`) informing
the user that their input must be of class `POSIXt`

```
msgid "'to' must be a \"POSIXt\" object"
msgstr "'to' muss ein \"POSIXt\" Objekt sein"
```

See this in context in the [`R-de.po` source file](https://svn.r-project.org/R/trunk/src/library/base/po/R-de.po).

The same message can also be found in
[`R-it.po`](https://svn.r-project.org/R/trunk/src/library/base/po/R-it.po)
giving the translation to Italian:

```
msgid "'to' must be a \"POSIXt\" object"
msgstr "'to' dev'essere un oggetto \"POSIXt\""
```

#### Plural messages

Some messages will have different translations depending on some input determined at run time (e.g., the `length()` of
an input object or the `nrow()` of a `data.frame`). This presents a challenge for translation, because different languages
have different rules for how to pluralize different ordinal
numbers[^See the [relevant section](https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html) of the `gettext` manual].
For example, English typically adds `s` to any quantity of items besides 1 (1 dog, 2 dog`s`, 100 dog`s`, even 0 dog`s`).
Chinese typically does not alter the word itself in similar situations (一只狗, 两只狗, 一百只狗, 零只狗); Arabic has _six_
different ways to pluralize a quantity.

In `.po` files, this shows up in the form of `msgid_plural` entries, followed by several ordered `msgstr` entries. Here's an example from
[`R-de.po`](https://github.com/r-devel/r-svn/blob/c715d61cb74b3fee2d035faed9b258e86e420b75/src/library/base/po/R-de.po#L2015-L2018):

```
msgid "Warning message:\n"
msgid_plural "Warning messages:\n"
msgstr[0] "Warnmeldung:\n"
msgstr[1] "Warnmeldungen:\n"
```

The two entries in English correspond to the singular and plural messages; the two entries in German correspond similarly, because
pluralization rules in German are similar to those in English. The situation in Lithuanian
([`R-lt.po`](https://github.com/r-devel/r-svn/blob/c715d61cb74b3fee2d035faed9b258e86e420b75/src/library/base/po/R-lt.po#L1999-L2003))
is more divergent:

```
msgid "Warning message:\n"
msgid_plural "Warning messages:\n"
msgstr[0] "Įspėjantis pranešimas:\n"
msgstr[1] "Įspėjantys pranešimai:\n"
msgstr[2] "Įspėjančių pranešimų:\n"
```

This corresponds to the 3 different ways to pluralize words in Polish.

What do `0`, `1`, and `2` correspond to, exactly? Ideally, this will be clear to native speakers of the language, but for
clarity, it is the solution to a small arithmetic problem that can be found in the language's metadata entry. Look for the
`Plural-Forms` entry in the metadata at the top of the `.po` file;
[here it is for Lithuanian](https://github.com/r-devel/r-svn/blob/c715d61cb74b3fee2d035faed9b258e86e420b75/src/library/base/po/R-lt.po#L18-L19):

```
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n"
"%100<10 || n%100>=20) ? 1 : 2);\n"
```

`nplurals` tells us how many entries correspond to each `msgid_plural` for this language. `plural` tells us, for the
quantity `n`, which entry to use. The arithmetic is C code; most important if you really want to parse this and are only
familiar with R code is C's [ternary operator](https://en.wikipedia.org/wiki/%3F:): `test ? valueIfTrue : valueIfFalse`
is a handy way to write R's `if (test) valueIfTrue else valueIfFalse`.

Parsing, we get the following associations:

- the `0` entry corresponds to when a number equals 1 modulo 10 (i.e., 1, 11, 21, 31, ...) _except_ numbers equaling
11 modulo 100 (i.e., 11, 111, 211, 311, ...). Combining, that's 1, 21, 31, ..., 91, 101, 121, 131, ..., 191, ...
- the `1` entry corresponds to numbers at least 2 modulo 10 (2, 3, ..., 8, 9, 12, 13, 14, ...) and _either_
below 10 modulo 100 (0, 1, ..., 9, 100, 101, ..., 109, ...) _or_ exceeding 20 modulo 100 (21, 22, ..., 99). Combining,
that's 2, 3, ..., 9, 22, 23, ..., 29, 32, 33, ... 39, ..., 102, 103, ..., 109, 122, 123, ...
- The `2` entry corresponds to all other numbers, i.e. 0, 10, 11, 12, ..., 19, 20, 30, ..., 90, 100, 110, 111, 112, ...

<!-- TODO(michaelchirico): How to discover a new `nplurals/plural`. -->
<!-- TODO(michaelchirico): sprintf templates (`%s`) and redirections (`%1$s`) -->
<!-- TODO(michaelchirico): fuzzy translations -->

### `.mo` files

`.po` files are plain text, but while helpful for human readers, this is inefficient for consumption by computers.
The .mo format is a "compiled" version of the .po file optimized for retrieving messages when R is running.

In R-devel, the conversion from .po to .mo is done by R Core -- you don't need to compile these files yourself.
They are stored in the R sources at `./src/library/translations/inst` in various language-specific subdirectories.

## How to contribute new translations

<!-- TODO(michaelchirico): Creating and editing .po files, testing the translations worked, **encoding**, translation teams, release schedule -->

## Current status of translations in R

https://contributor.r-project.org/translations/

## Helpful references

- Statistical terms glossary
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 22a7398

Please sign in to comment.