Skip to main content

Internationalization (i18n) support for Flower Celery monitoring tool

Project description

Flower i18n

🌍 为 Flower Celery 监控工具提供国际化(i18n)支持,让你的 Flower 界面支持中英文切换!

English | 中文


中文文档

简介

Flower i18n 是一个为 Flower Celery 监控工具添加国际化支持的 Python 包。它让你可以在 Flower 的 Web 界面中轻松切换中文和英文。

特性

  • ✅ 支持中英文界面切换
  • ✅ 自动检测浏览器语言
  • ✅ 记住用户语言偏好(通过 Cookie)
  • ✅ 简单的安装和配置流程
  • ✅ 不影响 Flower 的原有功能
  • ✅ 可扩展的翻译系统

安装

从源码安装

# 克隆或下载此项目
cd flower-i18n

# 安装包
pip install -e .

从 PyPI 安装(待发布)

pip install flower-i18n

快速开始

1. 自动打补丁(推荐)

安装完成后,运行自动打补丁命令:

flower-i18n-patch

这个命令会:

  • 自动备份原始的 Flower 模板文件
  • 修改必要的模板以支持国际化
  • 复制必要的静态文件(JavaScript)

2. 启动 Flower

正常启动 Flower:

celery -A your_app flower

或者使用自定义端口:

celery -A your_app flower --port=5555

3. 使用语言切换

打开 Flower 界面后,你会在导航栏看到一个语言切换下拉菜单。点击即可在中英文之间切换。

高级用法

在自定义 Handler 中使用

如果你有自定义的 Flower Handler,可以这样使用 i18n 功能:

from flower.views import BaseHandler
from flower_i18n import I18nHandler

class MyCustomHandler(I18nHandler, BaseHandler):
    def get(self):
        # 使用 self._() 方法翻译文本
        translated_text = self._('nav.workers')
        self.render('my_template.html', text=translated_text)

添加新的翻译

你可以扩展翻译文件来添加更多语言或翻译项。

编辑翻译文件:

  • 英文:flower_i18n/locales/en_US/messages.json
  • 中文:flower_i18n/locales/zh_CN/messages.json

格式如下:

{
  "my.key": "My Translation"
}

添加新语言

  1. flower_i18n/locales/ 下创建新的语言目录,例如 ja_JP(日语)
  2. 在该目录下创建 messages.json 文件
  3. 添加翻译内容
  4. 修改 flower_i18n/static/js/i18n.js 添加新语言选项

卸载

如果你想移除 i18n 支持并恢复原始的 Flower:

flower-i18n-unpatch

这会恢复所有原始的模板文件。

然后卸载包:

pip uninstall flower-i18n

项目结构

flower-i18n/
├── flower_i18n/
│   ├── __init__.py          # 包初始化
│   ├── i18n.py              # 核心国际化逻辑
│   ├── patcher.py           # 模板打补丁工具
│   ├── locales/
│   │   ├── en_US/
│   │   │   └── messages.json  # 英文翻译
│   │   └── zh_CN/
│   │       └── messages.json  # 中文翻译
│   ├── static/
│   │   └── js/
│   │       └── i18n.js      # 前端语言切换逻辑
│   └── templates/           # 自定义模板(如需要)
├── pyproject.toml           # 项目配置
├── setup.py                 # 安装脚本
├── LICENSE                  # MIT 许可证
└── README.md               # 本文档

贡献

欢迎贡献!如果你想添加新的语言支持或改进翻译,请:

  1. Fork 本项目
  2. 创建你的功能分支 (git checkout -b feature/AmazingFeature)
  3. 提交你的修改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 开启一个 Pull Request

常见问题

Q: 安装后看不到语言切换按钮?

A: 确保你运行了 flower-i18n-patch 命令,并且重启了 Flower。

Q: 切换语言后没有变化?

A: 请刷新页面(Ctrl+F5 或 Cmd+Shift+R)清除缓存。

Q: 如何添加更多翻译项?

A: 编辑 flower_i18n/locales/*/messages.json 文件,添加你需要的键值对。

Q: 会影响 Flower 的性能吗?

A: 不会。i18n 只在页面加载时执行,对性能影响可忽略不计。

许可证

MIT License - 详见 LICENSE 文件

致谢

  • Flower - 优秀的 Celery 监控工具
  • Celery - 分布式任务队列

English Documentation

Introduction

Flower i18n is a Python package that adds internationalization (i18n) support to the Flower Celery monitoring tool. It enables easy language switching between Chinese and English in the Flower web interface.

Features

  • ✅ Chinese and English language switching
  • ✅ Automatic browser language detection
  • ✅ Remember user language preference (via Cookie)
  • ✅ Simple installation and configuration
  • ✅ Does not affect Flower's original functionality
  • ✅ Extensible translation system

Installation

Install from source

# Clone or download this project
cd flower-i18n

# Install the package
pip install -e .

Install from PyPI (coming soon)

pip install flower-i18n

Quick Start

1. Auto-patch (Recommended)

After installation, run the auto-patch command:

flower-i18n-patch

This command will:

  • Automatically backup original Flower template files
  • Modify necessary templates to support i18n
  • Copy required static files (JavaScript)

2. Start Flower

Start Flower normally:

celery -A your_app flower

Or with a custom port:

celery -A your_app flower --port=5555

3. Use Language Switcher

After opening the Flower interface, you'll see a language switcher dropdown in the navigation bar. Click to switch between Chinese and English.

Advanced Usage

Using in Custom Handlers

If you have custom Flower handlers, you can use i18n features like this:

from flower.views import BaseHandler
from flower_i18n import I18nHandler

class MyCustomHandler(I18nHandler, BaseHandler):
    def get(self):
        # Use self._() method to translate text
        translated_text = self._('nav.workers')
        self.render('my_template.html', text=translated_text)

Adding New Translations

You can extend translation files to add more languages or translation entries.

Edit translation files:

  • English: flower_i18n/locales/en_US/messages.json
  • Chinese: flower_i18n/locales/zh_CN/messages.json

Format:

{
  "my.key": "My Translation"
}

Adding New Languages

  1. Create a new language directory under flower_i18n/locales/, e.g., ja_JP (Japanese)
  2. Create a messages.json file in that directory
  3. Add translation content
  4. Modify flower_i18n/static/js/i18n.js to add the new language option

Uninstall

If you want to remove i18n support and restore the original Flower:

flower-i18n-unpatch

This will restore all original template files.

Then uninstall the package:

pip uninstall flower-i18n

Project Structure

flower-i18n/
├── flower_i18n/
│   ├── __init__.py          # Package initialization
│   ├── i18n.py              # Core i18n logic
│   ├── patcher.py           # Template patching tool
│   ├── locales/
│   │   ├── en_US/
│   │   │   └── messages.json  # English translations
│   │   └── zh_CN/
│   │       └── messages.json  # Chinese translations
│   ├── static/
│   │   └── js/
│   │       └── i18n.js      # Frontend language switching logic
│   └── templates/           # Custom templates (if needed)
├── pyproject.toml           # Project configuration
├── setup.py                 # Setup script
├── LICENSE                  # MIT License
└── README.md               # This document

Contributing

Contributions are welcome! If you want to add new language support or improve translations:

  1. Fork this project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

FAQ

Q: Can't see the language switcher after installation?

A: Make sure you ran the flower-i18n-patch command and restarted Flower.

Q: No change after switching language?

A: Please refresh the page (Ctrl+F5 or Cmd+Shift+R) to clear cache.

Q: How to add more translation entries?

A: Edit flower_i18n/locales/*/messages.json files and add your key-value pairs.

Q: Will it affect Flower's performance?

A: No. i18n only executes during page load, with negligible performance impact.

License

MIT License - see LICENSE file for details

Acknowledgments

  • Flower - Excellent Celery monitoring tool
  • Celery - Distributed task queue

Star History

If you find this project useful, please consider giving it a star ⭐️

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flower_i18n-0.1.2.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flower_i18n-0.1.2-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file flower_i18n-0.1.2.tar.gz.

File metadata

  • Download URL: flower_i18n-0.1.2.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for flower_i18n-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8f75669eae8aded96bbd43b606ffb568553b62b7927199ca54e63a2216a445f2
MD5 aa217479b6839ec33c4fe082d4c8c0f2
BLAKE2b-256 ef2e1e46584965a5e2e50c30fc7c60e453f5549e193c95c8af7bcf4d08f34fe0

See more details on using hashes here.

File details

Details for the file flower_i18n-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: flower_i18n-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for flower_i18n-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0b9965c13af9828672efb3fdbb628a1e4b748e6930eb876b4210af1ae1b52a62
MD5 235ff1351c3749a97bbc51c2f22a297e
BLAKE2b-256 854f203d3d44feed63b80d901c6540fb6ef1490bd74266fa30d5d8103fb46d24

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page