feat(i18n): localize start/help/menu, practice, words, import, reminder, vocabulary, tasks/stats for RU/EN/JA; add JSON-based i18n helper\n\nfeat(lang): support learning/translation languages across AI flows; hide translations with buttons; store examples per lang\n\nfeat(vocab): add source_lang and translation_lang to Vocabulary, unique constraint (user_id, source_lang, word_original); filter /vocabulary by user.learning_language\n\nchore(migrations): add Alembic setup + migration to add vocab lang columns; env.py reads app settings and supports asyncpg URLs\n\nfix(words/import): pass learning_lang + translation_lang everywhere; fix menu themes generation\n\nfeat(settings): add learning language selector; update main menu on language change

This commit is contained in:
2025-12-04 19:40:01 +03:00
parent 6223351ccf
commit 472771229f
22 changed files with 1587 additions and 471 deletions

93
migrations/env.py Normal file
View File

@@ -0,0 +1,93 @@
from alembic import context
from sqlalchemy import engine_from_config, pool
from sqlalchemy.ext.asyncio import create_async_engine
from logging.config import fileConfig
import sys, os
# Ensure project root is on sys.path for importing config.settings
PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))
if PROJECT_ROOT not in sys.path:
sys.path.append(PROJECT_ROOT)
try:
from config.settings import settings
except Exception:
settings = None
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
target_metadata = None # not used, explicit migrations only
def _get_urls():
"""Derive a sync SQLAlchemy URL from app settings (async -> sync)."""
async_url = None
sync_url = None
if settings and getattr(settings, 'database_url', None):
async_url = settings.database_url
sync_url = async_url
if async_url.startswith("postgresql+asyncpg://"):
sync_url = async_url.replace("postgresql+asyncpg://", "postgresql://", 1)
return async_url, sync_url
def run_migrations_offline():
async_url, sync_url = _get_urls()
url = sync_url or config.get_main_option("sqlalchemy.url")
if url:
config.set_main_option("sqlalchemy.url", url)
context.configure(
url=url,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
async_url, sync_url = _get_urls()
# If we have an async URL, run migrations via async engine
if async_url and async_url.startswith("postgresql+asyncpg://"):
async def do_run_migrations():
connectable = create_async_engine(async_url, poolclass=pool.NullPool)
async with connectable.connect() as connection:
def sync_migrations(conn):
context.configure(connection=conn)
with context.begin_transaction():
context.run_migrations()
await connection.run_sync(sync_migrations)
import asyncio
asyncio.run(do_run_migrations())
return
# Fallback to sync engine (e.g., if sync URL is provided)
url = sync_url or config.get_main_option("sqlalchemy.url")
if url:
config.set_main_option("sqlalchemy.url", url)
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(connection=connection)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

View File

@@ -0,0 +1,30 @@
"""add source_lang and translation_lang to vocabulary
Revision ID: 20251204_add_vocab_lang
Revises:
Create Date: 2025-12-04
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '20251204_add_vocab_lang'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
op.add_column('vocabulary', sa.Column('source_lang', sa.String(length=5), nullable=True))
op.add_column('vocabulary', sa.Column('translation_lang', sa.String(length=5), nullable=True))
# Create unique constraint for (user_id, source_lang, word_original)
op.create_unique_constraint('uq_vocab_user_lang_word', 'vocabulary', ['user_id', 'source_lang', 'word_original'])
def downgrade():
op.drop_constraint('uq_vocab_user_lang_word', 'vocabulary', type_='unique')
op.drop_column('vocabulary', 'translation_lang')
op.drop_column('vocabulary', 'source_lang')