aiogram / i18n

31 stars 2 forks source link

[BUG] "Extract" comments already commented keys #33

Closed andrew000 closed 3 months ago

andrew000 commented 11 months ago

Foreword

Steps

For non-windows users - replace "\" with "/"

  1. python -m aiogram_i18n extract -i '.\bot' -o '.\locales\test.ftl' -cm -k 'i18n' --locales 'uk'
  2. Comment info_cmd() function in main.py
  3. Run command from step 1 (info-text = info-text will be commented in test.ftl)
  4. Comment help_cmd() function in main.py
  5. Run command from step 1 (help-text = help-text will be commented in test.ftl and # info-text = info-text will be commented twice)

Expected behavior

Keys should be:

# help-text = help-text
# info-text = info-text

Current behavior

If info-text = info-text was commented before - "Extract" will comment it again if we remove help-text = help-text from code and re-run extract process

Keys:

# help-text = help-text
# # info-text = info-text

Code to reproduce bug

import asyncio

from aiogram import Dispatcher, Bot
from aiogram.filters import Command
from aiogram.fsm.storage.memory import MemoryStorage
from aiogram.types import Message
from aiogram_i18n import I18nContext

dp = Dispatcher(storage=MemoryStorage())

@dp.message(Command("start"))
async def start_cmd(msg: Message, i18n: I18nContext) -> None:
    await msg.reply(i18n.get("hello-text"))

@dp.message(Command("help"))
async def help_cmd(msg: Message, i18n: I18nContext) -> None:
    await msg.reply(i18n.get("help-text"))

@dp.message(Command("info"))
async def info_cmd(msg: Message, i18n: I18nContext) -> None:
    await msg.reply(i18n.get("info-text"))

if __name__ == '__main__':
    bot = Bot(token="42")
    asyncio.run(dp.start_polling(bot))

Requiremets

aiogram==3.2.0
aiogram_i18n==1.3.3
libcst==1.1.0
andrew000 commented 3 months ago

Resolved in another lib