Skip to content

Commit

Permalink
Correct errors in multilingual guide (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyheppell authored Aug 8, 2024
1 parent aa8f449 commit 35e80da
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions docs/advanced/multilingual.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The correct parse of this picker should set the current language to English, add

Using the `self.page_doc` attribute, a [`BeautifulSoup`][bs4.BeautifulSoup] object representing the page, the root element of the picker should be found and returned.

The `select_one` method is used to find the root element, and will return `None` if no element is found, which will be intepreted as the picker not being present on the page.
The `select_one` method is used to find the root element, and will return `None` if no element is found, which will be interpreted as the picker not being present on the page.

If a value is returned, the `self.root_el` attribute will be populated with the result of this method.

Expand All @@ -92,15 +92,16 @@ If a value is returned, the `self.root_el` attribute will be populated with the
class MyPicker(LangPicker):
...
def get_root(self) -> Tag:
return self.page_doc.select_one('ul', class_='translations')
return self.page_doc.select_one('ul.translations')
```

### `extract()`

Using the `self.root_el` attribute, the languages should be found and added to the dataset.

Be careful to avoid:
- Adding the current language

- Adding the current language as a translation
- Adding languages which are listed but don't have translations

??? example "Example `extract` implementation"
Expand All @@ -112,11 +113,11 @@ Be careful to avoid:
for lang_el in self.root_el.select('li'):
lang_a = lang_el.select_one('a')
if 'current-lang' in lang_a.get('class'):
self.set_current_lang(lang)
self.set_current_lang(lang_a.get('lang'))
elif 'no-translation' not in lang_a.get('class'):
self.add_translation(lang_a.get('href'), lang_a.get('lang'))
```

### Contributing Pickers

We welcome contributions via a GitHub PR so long as the picker is not overly specific to a single site.
We welcome contributions via a GitHub PR so long as the picker is not overly specific to a single site.

0 comments on commit 35e80da

Please sign in to comment.