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

{time_difference} in different languages #13

Open
Belarrius1 opened this issue Apr 7, 2023 · 3 comments
Open

{time_difference} in different languages #13

Belarrius1 opened this issue Apr 7, 2023 · 3 comments
Assignees

Comments

@Belarrius1
Copy link

Hi!

First of all I must say that I LOVE this project very much, having my personal AI chatbot has always been my dream, and this project is a big part of that! So Thank You for that!!

I translated into French "ltm_config.json" and I see that there is only one problem: it is the text of "{time_difference}" it's "0 days ago" for exemple, so, in French, it's must be "il y a 0 jours"

It's not really a big problem since it's only time, but allowing it to be translated would be a good thing I think!

@wawawario2
Copy link
Owner

This is a good point, one way of addressing this is to add a custom config option that allows you to format how you word "X days ago". I'll think through this.

@wawawario2 wawawario2 self-assigned this Apr 8, 2023
@Belarrius1
Copy link
Author

Sounds like a good idea, thanks!

@Belarrius1
Copy link
Author

Here is what I use now:

I install this:

pip install deep-translator

And i modify the code of /utils/timestamp_parsing.py for

"""Timestamp parsing utils."""

import math
from datetime import datetime
from deep_translator import GoogleTranslator


def get_time_difference_message(past_timestamp: str) -> str:
    """Converts a timestamp from the past to a "X days ago" format."""
    datetime_format = "%Y-%m-%d %H:%M:%S"
    past = datetime.strptime(past_timestamp, datetime_format)
    now = datetime.utcnow()
    delta = now - past

    days = math.floor(delta.days)
    message = f"{days} days ago"
    translated_message = GoogleTranslator(source='en', target='fr').translate(message)
    return translated_message

You can change "fr" by anything you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants