[RFC PATCH 1/2] l10n: add .gitattributes to simplify location filtering
- From
Jiang Xin <worldhello.net@gmail.com>
- Date
- Feb 5, 2026, 13:00 UTC
- Message-ID
- <00d6cbf44f88fbd402375a2d41d7f9059d339e5d.1770296405.git.worldhello.net@gmail.com>
- In-Reply-To
- <CANYiYbFhshDwfttKWYGDfO+K1qAz3ptVHuuHrWXhD2oYBF7baQ@mail.gmail.com>
To simplify the location filtering process for l10n contributors when committing po/XX.po files, add the filter attributes for .po files to the repository. This ensures all contributors automatically get the same filter configuration without manual setup in .git/info/attributes.
Contributors still need to manually define the filter drivers using git-config as documented in po/README.md.
Signed-off-by: Jiang Xin <worldhello.net@gmail.com> --- po/.gitattributes | 37 +++++++++++++++++++++++++++++++++++++ po/README.md | 19 +++++++++++-------- 2 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 po/.gitattributes
diff --git a/po/.gitattributes b/po/.gitattributes new file mode 100644 index 0000000000..1a83c8027c --- /dev/null +++ b/po/.gitattributes @@ -0,0 +1,37 @@ +# Git Attributes for PO Files +# +# This file configures Git filters to automatically strip location information +# from PO files when committing, producing cleaner diffs and saving repository +# space. +# +# Two filter types are used: +# 1. gettext-no-file-no-location: Strips both filenames and line numbers +# (e.g., removes "#: main.c:123" entirely) +# 2. gettext-no-location: Preserves filenames but removes line numbers, which +# requires gettext 0.20 or higher +# (e.g., "#: main.c:123" becomes "#: main.c") +# +# See `po/README.md` for instructions on setting up the required filter drivers. + +# Default: Strip both filenames and locations for all .po files +*.po filter=gettext-no-file-no-location + +# Explicitly documented languages using the default filter +# (These inherit the *.po rule above but are listed here for documentation) +bg.po filter=gettext-no-file-no-location +de.po filter=gettext-no-file-no-location +es.po filter=gettext-no-file-no-location +fr.po filter=gettext-no-file-no-location +ga.po filter=gettext-no-file-no-location +ru.po filter=gettext-no-file-no-location +sv.po filter=gettext-no-file-no-location +tr.po filter=gettext-no-file-no-location +uk.po filter=gettext-no-file-no-location +vi.po filter=gettext-no-file-no-location + +# Languages that preserve filenames but strip line numbers +# (These override the *.po rule above with a different filter) +ca.po filter=gettext-no-location +id.po filter=gettext-no-location +zh_CN.po filter=gettext-no-location +zh_TW.po filter=gettext-no-location diff --git a/po/README.md b/po/README.md index ec08aa24ad..ad7f72ba83 100644 --- a/po/README.md +++ b/po/README.md @@ -166,23 +166,26 @@ and make a user-friendly patch for review. To save a location-less "po/XX.po" automatically in repository, you can: -First define a new attribute for "po/XX.po" by appending the following -line in ".git/info/attributes": +First, check which filter is configured for your "po/XX.po" file: ``` -/po/XX.po filter=gettext-no-location +git check-attr filter po/XX.po ``` -Then define the driver for the "gettext-no-location" clean filter to -strip out both filenames and locations from the contents as follows: +The filter configuration is defined in the "po/.gitattributes" file. + +Then define the driver for the filter. Most languages use the +"gettext-no-file-no-location" clean filter, which strips out both filenames and +locations from the comments. To set this up, run the following command: ```shell -git config --global filter.gettext-no-location.clean \ +git config --global filter.gettext-no-file-no-location.clean \ "msgcat --no-location -" ``` -For users who have gettext version 0.20 or higher, it is also possible -to define a clean filter to preserve filenames but not locations: +Some languages use the "gettext-no-location" clean filter, which preserves +filenames but not locations. For these, install gettext version 0.20 or higher +and setup the driver as below: ```shell git config --global filter.gettext-no-location.clean \
-- 2.51.0.rc2