Skip to content

Update README.rst#116

Open
yopiti wants to merge 1 commit into
izimobil:masterfrom
yopiti:patch-1
Open

Update README.rst#116
yopiti wants to merge 1 commit into
izimobil:masterfrom
yopiti:patch-1

Conversation

@yopiti

@yopiti yopiti commented Jan 14, 2022

Copy link
Copy Markdown

Adding example on how to save a modified entry, as this is no where documented and for starters requires a lot of time to find.

Adding example on how to save a modified entry, as this is no where documented and for starters requires a lot of time to find.
@kthy

kthy commented Jan 14, 2022

Copy link
Copy Markdown
Contributor

You probably don't want to save for each entry. Suggest moving the second line you added out of the for loop.

@codecov-commenter

codecov-commenter commented Feb 2, 2022

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.28%. Comparing base (8eb8e3f) to head (77dc74a).
⚠️ Report is 46 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #116   +/-   ##
=======================================
  Coverage   95.28%   95.28%           
=======================================
  Files           1        1           
  Lines         849      849           
=======================================
  Hits          809      809           
  Misses         40       40           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@izimobil

Copy link
Copy Markdown
Owner

@kthy is right, please update the PR to match a real usecase, thanks !

@MestreLion

MestreLion commented Dec 20, 2024

Copy link
Copy Markdown
Contributor

@kthy is right, please update the PR to match a real usecase, thanks !

Indeed, no one would realistically want to set all entries to the same, fixed string. (and surely not save after every entry. Besides, po doesn't exist, the name in that example is pofile)

My suggestion:

  • Revert the changes to that loop. Reading entries (specially in a loop) and modifying some to add translations are usually distinct steps anyway.
  • Add a new step to fetch distinct, arbitrary entries (showing how you can do it, using .find(), [i], etc.)
  • Change the msgstr for those retrieved entries
  • Save the file

Something like this:

for entry in pofile:
    print(entry.msgid, entry.msgstr)

entry = pofile.find("foo")  # by default it searches by msgid
if entry is not None:
    entry.msgstr = "bar"
    pofile.save('/path/to/pofile.po')  # or simply pofile.save() to overwrite
    pofile.save_as_mofile('/path/to/mofile.mo')  # automatically compiles to `.mo` !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants