mondeja / mdpo

Markdown files translation using GNU PO files
https://mondeja.github.io/mdpo/
BSD 3-Clause "New" or "Revised" License
25 stars 5 forks source link

Use rspolib instead of polib #225

Open mondeja opened 2 years ago

mondeja commented 2 years ago

Looks like possible and should improve performance. See https://launchpad.net/pygettextpo

To read PO files without defined charset "MIME-Version: 1.0\\n"\n"Content-Type: text/plain; charset=utf-8\\n" must be added to the headers or the next error will be raised:

Error ```pycon >>> gettextpo.PoFile('example.po') Traceback (most recent call last): File "", line 1, in gettextpo.error: Charset missing in header. Message conversion to user's charset will not work. ```

It seems that would fix #153

Example #### Input ```po # msgid "" msgstr "" "Project-Id-Version: Python 3.8\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-10-16 21:42+0200\n" "PO-Revision-Date: 2021-08-02 19:31+0200\n" "Last-Translator: \n" "Language-Team: python-doc-es\n" "Language: es\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" "Generated-By: Babel 2.9.1\n" msgid "" "Support for common temperature sensors (eg, common thermistors, " "AD595, AD597, AD849x, PT100, PT1000, MAX6675, MAX31855, MAX31856, " "MAX31865, BME280, HTU21D, and LM75). Custom thermistors and custom " "analog temperature sensors can also be configured." msgstr "" "支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以配置自定义热敏电阻和自定义模拟温度传感器。" ``` #### Code ```python >>> po = gettextpo.PoFile('input.po') >>> po.write('output.po') ``` #### Output ```po # msgid "" msgstr "" "Project-Id-Version: Python 3.8\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-10-16 21:42+0200\n" "PO-Revision-Date: 2021-08-02 19:31+0200\n" "Last-Translator: \n" "Language-Team: python-doc-es\n" "Language: es\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" "Generated-By: Babel 2.9.1\n" msgid "" "Support for common temperature sensors (eg, common thermistors, AD595, " "AD597, AD849x, PT100, PT1000, MAX6675, MAX31855, MAX31856, MAX31865, BME280, " "HTU21D, and LM75). Custom thermistors and custom analog temperature sensors " "can also be configured." msgstr "" "支持常见的温度传感器(例如,常见的热敏电阻、AD595、AD597、AD849x、PT100、" "PT1000、MAX6675、MAX31855、MAX31856、MAX31865、BME280、HTU21D和LM75)。还可以" "配置自定义热敏电阻和自定义模拟温度传感器。" ```
mondeja commented 1 year ago

I've done some tests in a local branch. Seems that the current implementation of the library is not enough complete. Create the same interface of polib using the library at C level would be the greatest improvement.

mondeja commented 1 year ago

After the developing of md-ulb-pwrap I'm thinking that the best option to optimize the usage of polib is rewriting the library as a CPython extension with Rust.

mondeja commented 7 months ago

I've written rspolib some months ago, so use that.