wikiquotes-python-api icon indicating copy to clipboard operation
wikiquotes-python-api copied to clipboard

Otras idiomas

Open gcqmkm02 opened this issue 4 years ago • 3 comments

Me gustaría hacer esto por el Frances, Koreano y otras idiomas. Es dificil?

gcqmkm02 avatar Aug 25 '21 13:08 gcqmkm02

@gcqmkm02 Disculpame, nunca vi este issue

FranDepascuali avatar May 03 '25 19:05 FranDepascuali

@kamara how difficult would it be to support another languages?

FranDepascuali avatar May 03 '25 19:05 FranDepascuali

🔍 Analysis for Issue #4

Adding support for additional languages like French and Korean to the wikiquotes-python-api is certainly possible, but requires some specific work. Here's what would be needed:

Implementation Requirements

  1. Create new language modules: You would need to create new Python files in the wikiquotes/languages/ directory (similar to english.py and spanish.py) for each language you want to support. For example:

    • french.py
    • korean.py
  2. Each language module needs to define:

    • base_url pointing to the appropriate Wikiquote API (e.g., "https://fr.wikiquote.org/w/api.php" for French)
    • quote_of_the_day_url for the language's quote of the day page
    • A quote_of_the_day_parser() function that can extract quotes from the HTML structure of that language's Wikiquote page
    • non_quote_sections list with section names to exclude (in that language)
  3. Update the language manager: Modify language_manager.py to recognize and support the new languages in the from_string() function.

Challenges

The main challenge is that each language's Wikiquote page may have a different HTML structure. You'll need to:

  1. Analyze the HTML structure of each language's Wikiquote pages
  2. Create custom parsing logic for each language (especially for the quote of the day feature)
  3. Identify the non-quote sections in each language

Example for French

For French, you might create a file like:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

base_url = "https://fr.wikiquote.org/w/api.php"
quote_of_the_day_url = "https://fr.wikiquote.org/wiki/Wikiquote:Citation_du_jour"

def quote_of_the_day_parser(html):
    # This would need to be customized based on the actual HTML structure
    # of the French Wikiquote page
    # ...
    return (quote, author)

non_quote_sections = ["à propos", "références", "liens externes"]

Then update the language manager to recognize French:

elif lowered == u"fr" or lowered == u"french" or lowered == u"francais":
    return french

Difficulty Level

The difficulty is moderate:

  • The framework for adding languages is already in place
  • The main work is understanding the HTML structure of each language's Wikiquote pages
  • Testing would be needed to ensure proper handling of different character sets (especially for Korean)

Would you like me to provide more specific guidance for implementing any particular language?

📁 Files Examined

View Files
  • wikiquotes/languages/__init__.py
  • wikiquotes/languages/english.py
  • wikiquotes/languages/spanish.py
  • wikiquotes/managers/language_manager.py
  • wikiquotes/wikiquotes_api.py
📋 Available Kamara Commands

You can use the following commands in your comments:

  • @kamara implement this - Request Kamara to implement this feature or fix
  • @kamara analyze this - Request Kamara to analyze this issue (default when mentioning Kamara)

Powered by Kamara AI - Your GitHub Assistant

kamara-ai[bot] avatar May 03 '25 19:05 kamara-ai[bot]