Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct errors in multilingual guide #45

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.