Skip to content

Commit 1f2588d

Browse files
committed
l10n: add .gitattributes to simplify location filtering
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>
1 parent 3df8d07 commit 1f2588d

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

po/.gitattributes

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Git Attributes for PO Files
2+
#
3+
# This file configures Git filters to automatically strip location information
4+
# from PO files when committing, producing cleaner diffs and saving repository
5+
# space.
6+
#
7+
# Two filter types are used:
8+
# 1. gettext-no-file-no-location: Strips both filenames and line numbers
9+
# (e.g., removes "#: main.c:123" entirely)
10+
# 2. gettext-no-location: Preserves filenames but removes line numbers, which
11+
# requires gettext 0.20 or higher
12+
# (e.g., "#: main.c:123" becomes "#: main.c")
13+
#
14+
# See `po/README.md` for instructions on setting up the required filter drivers.
15+
16+
# Default: Strip both filenames and locations for all .po files
17+
*.po filter=gettext-no-file-no-location
18+
19+
# Explicitly documented languages using the default filter
20+
# (These inherit the *.po rule above but are listed here for documentation)
21+
bg.po filter=gettext-no-file-no-location
22+
de.po filter=gettext-no-file-no-location
23+
es.po filter=gettext-no-file-no-location
24+
fr.po filter=gettext-no-file-no-location
25+
ga.po filter=gettext-no-file-no-location
26+
ru.po filter=gettext-no-file-no-location
27+
sv.po filter=gettext-no-file-no-location
28+
tr.po filter=gettext-no-file-no-location
29+
uk.po filter=gettext-no-file-no-location
30+
vi.po filter=gettext-no-file-no-location
31+
32+
# Languages that preserve filenames but strip line numbers
33+
# (These override the *.po rule above with a different filter)
34+
ca.po filter=gettext-no-location
35+
id.po filter=gettext-no-location
36+
zh_CN.po filter=gettext-no-location
37+
zh_TW.po filter=gettext-no-location

po/README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,23 +166,26 @@ and make a user-friendly patch for review.
166166
To save a location-less "po/XX.po" automatically in repository, you
167167
can:
168168

169-
First define a new attribute for "po/XX.po" by appending the following
170-
line in ".git/info/attributes":
169+
First, check which filter is configured for your "po/XX.po" file:
171170

172171
```
173-
/po/XX.po filter=gettext-no-location
172+
git check-attr filter po/XX.po
174173
```
175174

176-
Then define the driver for the "gettext-no-location" clean filter to
177-
strip out both filenames and locations from the contents as follows:
175+
The filter configuration is defined in the "po/.gitattributes" file.
176+
177+
Then define the driver for the filter. Most languages use the
178+
"gettext-no-file-no-location" clean filter, which strips out both filenames and
179+
locations from the comments. To set this up, run the following command:
178180

179181
```shell
180-
git config --global filter.gettext-no-location.clean \
182+
git config --global filter.gettext-no-file-no-location.clean \
181183
"msgcat --no-location -"
182184
```
183185

184-
For users who have gettext version 0.20 or higher, it is also possible
185-
to define a clean filter to preserve filenames but not locations:
186+
Some languages use the "gettext-no-location" clean filter, which preserves
187+
filenames but not locations. For these, install gettext version 0.20 or higher
188+
and setup the driver as below:
186189

187190
```shell
188191
git config --global filter.gettext-no-location.clean \

0 commit comments

Comments
 (0)