Your missing PO formatter and linter

Overview

pofmt

Tests pypi version pre-commit Code style: black

Your missing PO formatter and linter

Features

  • Wrap msgid and msgstr with a constant max width.
  • Can act as a pre-commit hook.
  • Display lint errors in a human readable format.
  • Insert white-spaces between Chinese characters and latin letters with pangu
  • The widths of CJK characters are multiplied by a factor for visual balance.

Requirements

pofmt requires Python >=3.6

Installation

It is recommended to install with pipx, if pipx haven't been installed yet, refer to the pipx's docs

$ pipx install pofmt

Alternatively, install with pip to the user site:

$ python -m pip install --user pofmt

If you are formatting PO files with Chinese, it is recommended to install pofmt[zh]. This includes a handy function to add spaces between CJK characters and latin letters.

As a pre-commit hook

See pre-commit for instructions.

A sample .pre-commit-config.yaml:

- repo: https://github.com/frostming/pofmt
  rev: '0.1.0'
  hooks:
    - id: pofmt
      additional_dependencies: ['pangu']  # for handling Chinese documents

Usage

USAGE: pofmt [-h] [--line-length LINE_LENGTH] [-c] [--cjk-width CJK_WIDTH] [filename ...]

Format PO files for consistency

positional arguments:
  filename              Filenames to format, default to all po files under the current directory(recursively)

optional arguments:
  -h, --help            show this help message and exit
  --line-length LINE_LENGTH
                        The max length of msgid and msgstr
  -c, --check           Check only, don't modify files
  --cjk-width CJK_WIDTH
                        The width factor of a CJK character, default: 1.8
  --no-msgid            Don't format msgid

Sample output

`_" -msgstr "`Jinja文档`_" +msgstr "`Jinja 文档 `_" #: ../../index.rst:23 msgid "`Werkzeug documentation `_" -msgstr "`Werkzeug文档`_" +msgstr "`Werkzeug 文档 `_" #: ../../index.rst:30 msgid "User's Guide" -msgstr "" -"用户指南" +msgstr "用户指南" #: ../../index.rst:32 msgid "" "This part of the documentation, which is mostly prose, begins with some " "background information about Flask, then focuses on step-by-step " "instructions for web development with Flask." -msgstr "" -"这部分的文档大部分是独立章节,以一些关于 Flask 的背景信息开始,然后重点介绍如何" -"使用 Flask 一步步进行 Web 开发。" +msgstr "这部分的文档大部分是独立章节,以一些关于 Flask 的背景信息开始,然后重点介绍如何使用 Flask 一步步进行 Web 开发。" #: ../../index.rst:66 msgid "API Reference" @@ -73,13 +72,13 @@ msgid "" "If you are looking for information on a specific function, class or " "method, this part of the documentation is for you." -msgstr "" -"如果你想找关于某个特定函数、类或方法的信息,那么这部分文档就是为你准备的。" +msgstr "如果你想找关于某个特定函数、类或方法的信息,那么这部分文档就是为你准备的。" #: ../../index.rst:78 msgid "Additional Notes" msgstr "附加笔记" #: ../../index.rst:80 -msgid "Design notes, legal information and changelog are here for the interested." +msgid "" +"Design notes, legal information and changelog are here for the interested." msgstr "如果你感兴趣的话,这里有一些设计笔记、法律信息和变更日志(changelog)。" ">
--- Original
+++ Current
@@ -21,49 +21,48 @@
 msgid "Welcome to Flask"
 msgstr "欢迎来到 Flask 的世界"

-msgid "Flask: web development, one "drop" at a time"
+msgid "Flask: web development, one \"drop\" at a time"
 msgstr "Flask: Web 开发,一次一滴"

 #: ../../index.rst:11
 msgid ""
-"Welcome to Flask's documentation. Get started with :doc:`installation` "
-"and then get an overview with the :doc:`quickstart`. There is also a more"
-" detailed :doc:`tutorial/index` that shows how to create a small but "
+"Welcome to Flask's documentation. Get started with :doc:`installation` and"
+" then get an overview with the :doc:`quickstart`. There is also a more "
+"detailed :doc:`tutorial/index` that shows how to create a small but "
 "complete application with Flask. Common patterns are described in the "
 ":doc:`patterns/index` section. The rest of the docs describe each "
 "component of Flask in detail, with a full reference in the :doc:`api` "
 "section."
 msgstr ""
-"欢迎来到Flask的文档。你可以从 :doc:`installation` 入手,然后阅读:doc:`quickstart`来了解基本概念。还有一个包含更多细节的:doc:`tutorial/index`"
-"介绍如何用Flask创建一个很小但是完整的程序。一般的开发模式可以在:doc:`patterns/index`章节找到。剩下的文档详细的介绍了Flask的每一个组成部件,"
-"其中:doc:`api`章节包括完整的API参考信息。"
+"欢迎来到 Flask 的文档。你可以从 :doc:`installation` 入手,然后阅读:doc:`quickstart` "
+"来了解基本概念。还有一个包含更多细节的:doc:`tutorial/index` 介绍如何用 Flask "
+"创建一个很小但是完整的程序。一般的开发模式可以在:doc:`patterns/index` 章节找到。剩下的文档详细的介绍了 Flask "
+"的每一个组成部件,其中:doc:`api` 章节包括完整的 API 参考信息。"

 #: ../../index.rst:19
-msgid "Flask depends on the `Jinja`_ template engine and the `Werkzeug`_ WSGI toolkit. The documentation for these libraries can be found at:"
-msgstr ""
-"Flask 依赖 `Jinja`_ 模板引擎和 `Werkzeug`_ WSGI 工具集。这些库的文档如下:"
+msgid ""
+"Flask depends on the `Jinja`_ template engine and the `Werkzeug`_ WSGI "
+"toolkit. The documentation for these libraries can be found at:"
+msgstr "Flask 依赖 `Jinja`_ 模板引擎和 `Werkzeug`_ WSGI 工具集。这些库的文档如下:"

 #: ../../index.rst:22
 msgid "`Jinja documentation `_"
-msgstr "`Jinja文档`_"
+msgstr "`Jinja 文档 `_"

 #: ../../index.rst:23
 msgid "`Werkzeug documentation `_"
-msgstr "`Werkzeug文档`_"
+msgstr "`Werkzeug 文档 `_"

 #: ../../index.rst:30
 msgid "User's Guide"
-msgstr ""
-"用户指南"
+msgstr "用户指南"

 #: ../../index.rst:32
 msgid ""
 "This part of the documentation, which is mostly prose, begins with some "
 "background information about Flask, then focuses on step-by-step "
 "instructions for web development with Flask."
-msgstr ""
-"这部分的文档大部分是独立章节,以一些关于 Flask 的背景信息开始,然后重点介绍如何"
-"使用 Flask 一步步进行 Web 开发。"
+msgstr "这部分的文档大部分是独立章节,以一些关于 Flask 的背景信息开始,然后重点介绍如何使用 Flask 一步步进行 Web 开发。"

 #: ../../index.rst:66
 msgid "API Reference"
@@ -73,13 +72,13 @@
 msgid ""
 "If you are looking for information on a specific function, class or "
 "method, this part of the documentation is for you."
-msgstr ""
-"如果你想找关于某个特定函数、类或方法的信息,那么这部分文档就是为你准备的。"
+msgstr "如果你想找关于某个特定函数、类或方法的信息,那么这部分文档就是为你准备的。"

 #: ../../index.rst:78
 msgid "Additional Notes"
 msgstr "附加笔记"

 #: ../../index.rst:80
-msgid "Design notes, legal information and changelog are here for the interested."
+msgid ""
+"Design notes, legal information and changelog are here for the interested."
 msgstr "如果你感兴趣的话,这里有一些设计笔记、法律信息和变更日志(changelog)。"
You might also like...
An assistant to guess your pip dependencies from your code, without using a requirements file.

Pip Sala Bim is an assistant to guess your pip dependencies from your code, without using a requirements file. Pip Sala Bim will tell you which packag

Helper to organize your windows on your desktop.
Helper to organize your windows on your desktop.

The script of positionsing windows on the screen. How does it work? Select your window to move/res

Display your data in an attractive way in your notebook!
Display your data in an attractive way in your notebook!

Bloxs Bloxs is a simple python package that helps you display information in an attractive way (formed in blocks). Perfect for building dashboards, re

Your copilot to studies and work (Pomodoro-timer, Translate and Notes app)

Copylot Your copilot to studies and work (Pomodoro-timer, Translate and Notes app) Copylot are three applications in one: Pomodoro Translate Notes Cop

Inspect the resources of your android projects and understand which ones are not being used and could potentially be removed.
Inspect the resources of your android projects and understand which ones are not being used and could potentially be removed.

Android Resources Checker What This program will inspect the resources of your app and help you understand which ones are not being used and could pot

Secret santa is a fun and easy way to get together with your friends and/or family with a gift for them.

Secret Santa What is Secret Santa? Secret santa is a fun and easy way to get together with your friends and/or family with a gift for them. The idea i

A beautiful and useful prompt for your shell
A beautiful and useful prompt for your shell

A Powerline style prompt for your shell A beautiful and useful prompt generator for Bash, ZSH, Fish, and tcsh: Shows some important details about the

Comments
  • Split at CJK punctuations

    Split at CJK punctuations

    Chinese symbols | rule | Chinese symbols | rule -- | -- | -- | -- ( | \uff08 | ) | \uff09 〈 | \u3008 | 〉 | \u3009 《 | \u300a | 》 | \u300b 「 | \u300c | 」 | \u300d 『 | \u300e | 』 | \u300f ﹃ | \ufe43 | ﹄ | \ufe44 〔 | \u3014 | 〕 | \u3015 … | \u2026 | — | \u2014 ~ | \uff5e | ﹏ | \ufe4f ¥ | \uffe5 | 、 | \u3001 【 | \u3010 | 】 | \u3011 , | \uff0c | 。 | \u3002 ? | \uff1f | ! | \uff01 : | \uff1a | ; | \uff1b “ | \u201c | ” | \u201d ‘ | \u2018 | ’ | \u2019

    opened by frostming 1
  • Add an option to turn off the format of msgid

    Add an option to turn off the format of msgid

    Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

    Describe the solution you'd like A clear and concise description of what you want to happen.

    Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

    Additional context Add any other context or screenshots about the feature request here.

    opened by frostming 0
  • fuzzy messages cause parse error: Missing msgstr

    fuzzy messages cause parse error: Missing msgstr

    Describe the bug When there is a fuzzy entry in a .po file, it causes a parse error like

    To Reproduce Steps to reproduce the behavior:

    1. Create a test.po file like below
    2. Run command 'pofmt ./test.po'
    3. See error "❌ ./test.po Parse error: line 2: Missing msgstr"
    #: path/to/file.html:136
    #, fuzzy
    #| msgid "Report (HTML)"
    msgid "Report HTML"
    msgstr "Informe (HTML)"
    

    Expected behavior Ignore the fuzzy comments, or fail indicating fuzzy are not supported

    Screenshots

    System (please complete the following information):

    • pofmt version: 0.3.0
    • Python version: 3.7
    • OS: Windows

    Additional context

    opened by jayvdb 0
Owner
Frost Ming
Love 🐍 Python, 📷 Photography and beautiful things
Frost Ming
These are the scripts used for the project of ‘Assembly of a pan-genome for global cattle reveals missing sequence and novel structural variation, providing new insights into their diversity and evolution history’

script-SV-genotyping These are the scripts used for the project of ‘Assembly of a pan-genome for global cattle reveals missing sequence and novel stru

null 2 Aug 26, 2022
Blender addon that simplifies access to useful operators and adds missing functionality

Quick Menu is a Blender addon that simplifies common tasks Compatible with Blender 3.x.x Install through Edit -> Preferences -> Addons -> Install... -

passivestar 94 Dec 27, 2022
Its a simple and fun to use application. You can make your own quizes and send the lik of the quiz to your friends.

Quiz Application Its a simple and fun to use application. You can make your own quizes and send the lik of the quiz to your friends. When they would a

Atharva Parkhe 1 Feb 23, 2022
Purge your likes and wall comments from VKontakte. Set yourself free from your digital footprint.

vk_liberator Regain liberty in the cruel social media world. This program assists you with purging your metadata from Russian social network VKontakte

null 20 Jun 11, 2021
🗽 Like yarn outdated/upgrade, but for pip. Upgrade all your pip packages and automate your Python Dependency Management.

pipupgrade The missing command for pip Table of Contents Features Quick Start Usage Basic Usage Docker Environment Variables FAQ License Features Upda

Achilles Rasquinha 529 Dec 31, 2022
Add your recently blog and douban states in your GitHub Profile

Add your recently blog and douban states in your GitHub Profile

Bingjie Yan 4 Dec 12, 2022
edgetest is a tox-inspired python library that will loop through your project's dependencies, and check if your project is compatible with the latest version of each dependency

Bleeding edge dependency testing Full Documentation edgetest is a tox-inspired python library that will loop through your project's dependencies, and

Capital One 16 Dec 7, 2022
An app that mirrors your phone to your compute and maps controller input to the screen

What is 'Dragalia Control'? An app that mirrors your phone to your compute and maps controller input to the screen. Inputs are mapped specifically for

null 1 May 3, 2022
switching computer? changing your setup? You need to automate the download of your current setup? This is the right tool for you :incoming_envelope:

?? setup_shift(SS.py) switching computer? changing your setup? You need to automate the download of your current setup? This is the right tool for you

Mohamed Elfaleh 15 Aug 26, 2022
A python tool that creates issues in your repos based on TODO comments in your code

Krypto A neat little sidekick python script to create issues on your repo based on comments left in the code on your behalf Convert todo comments in y

Alex Antoniou 4 Oct 26, 2021