Skip to content

Commit

Permalink
fix: not working when added to INSTALLED_APPS
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyteles committed Oct 9, 2024
1 parent b9918ee commit 33df4cf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 32 deletions.
14 changes: 6 additions & 8 deletions django_lexpy/apps.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import os
from pathlib import Path

from django.apps import AppConfig

from django_lexpy.commands import lexpy


class LexpyConfig(AppConfig):
name = "django_lexpy"
label = "lexpy"

def __init__(self):
self.dir_project = os.getcwd()
verbose_name = "django-lexpy"
dir_project = os.getcwd()

def get(self):
return self.dir_project
def ready(self):
lexpy.main()
17 changes: 3 additions & 14 deletions django_lexpy/commands/lexpy.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
import os
import rich
import typer
import shutil
import django

from django.conf import settings
from django_lexpy.apps import LexpyConfig
from django.apps import apps

app = typer.Typer()
settings.configure()

@app.command()
def main():
config = LexpyConfig()

rich.print("[green]Initializing lexpy...[/green]")

# if the parameter is not given, get the LANGUAGE_CODE from settings.py
language = settings.LANGUAGE_CODE.replace("-", "_")

# Store path to a specific folder messages
base_dir = os.path.join(config.get(), 'lang', language)
base_dir = os.path.join(apps.get_app_config('django_lexpy').dir_project, 'lang', language)

if not os.path.exists(base_dir):

# Make directories
os.makedirs(base_dir, exist_ok=True)

Expand All @@ -37,7 +30,3 @@ def main():
rich.print("[red]Files not found to copy...[/red]")

rich.print("[green]Done![/green]")


if __name__ == "__main__":
app()
14 changes: 8 additions & 6 deletions django_lexpy/templatetags/lexpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

register = template.Library()

# Get language code from settings
language_settings = settings.LANGUAGE_CODE.replace("-", "_")

lang_module = importlib.import_module(f'lang.{language_settings}')
messages = lang_module.messages


@register.simple_tag
def lexpy(message):
# Get language code from settings
language_settings = settings.LANGUAGE_CODE.replace("-", "_")

# Load messages package
lang_module = importlib.import_module(f'lang.{language_settings}')
messages = lang_module.messages

command = message.split(".")

assert len(command) == 2, "Your call are wrong, try something like 'message.welcome'"
Expand All @@ -27,3 +28,4 @@ def lexpy(message):
assert message in messages, "This message don't exists!"

return messages.get(message)

7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
[tool.poetry]
name = "django-lexpy"
version = "0.1.0"
version = "0.1.1"
description = "Organize your texts and languages in a simple way."
authors = ["audreyteles <audreytelesdossantos@gmail.com>"]
classifiers = ['Framework :: Django', 'Programming Language :: Python :: 3']
license = "MIT"

[tool.poetry.dependencies]
python = "==3.12.3"
django = ">=4.2,<5.2"
typer = ">=0.12.5"
python = ">=3.8"
django = ">=5.0"
rich = ">=13.9.2"

[build-system]
Expand Down

0 comments on commit 33df4cf

Please sign in to comment.