Skip to content

Add %lang() support for locale files in RPM packages #1036

@janderssonse

Description

@janderssonse

Is your feature request related to a problem? Please describe.

When packaging locale files (.mo files in /usr/share/locale/), nfpm doesn't support
the RPM %lang() directive.

rpmlint reports:
W: file-not-in-%lang /usr/share/locale/en/LC_MESSAGES/myapp.mo
W: file-not-in-%lang /usr/share/locale/sv/LC_MESSAGES/myapp.mo

The %lang() directive allows users to selectively install only needed translations via
RPM's %install_langs configuration, saving disk space.

Expected: Locale files should be marked with their respective language tag.

How can we reproduce this?

  1. Create locale files:
    locale/en/LC_MESSAGES/myapp.mo
    locale/sv/LC_MESSAGES/myapp.mo

  2. Create nfpm.yaml:

name: myapp
version: 1.0.0
maintainer: Name <email@example.com>
description: Example package
contents:
  - src: ./locale/en/LC_MESSAGES/myapp.mo
    dst: /usr/share/locale/en/LC_MESSAGES/myapp.mo
  - src: ./locale/sv/LC_MESSAGES/myapp.mo
    dst: /usr/share/locale/sv/LC_MESSAGES/myapp.mo

3. Build: nfpm package -p rpm
4. Check: rpmlint myapp-1.0.0.x86_64.rpm

Result:
W: file-not-in-%lang /usr/share/locale/en/LC_MESSAGES/myapp.mo
W: file-not-in-%lang /usr/share/locale/sv/LC_MESSAGES/myapp.mo

Expected RPM spec output:
%lang(en) /usr/share/locale/en/LC_MESSAGES/myapp.mo
%lang(sv) /usr/share/locale/sv/LC_MESSAGES/myapp.mo

### Describe the solution you'd like

Add a `lang` field to content entries (RPM-specific, ignored by other packagers):

```yaml
contents:
  - src: ./locale/en/LC_MESSAGES/myapp.mo
    dst: /usr/share/locale/en/LC_MESSAGES/myapp.mo
    lang: en   # generates %lang(en) in RPM spec
  - src: ./locale/sv/LC_MESSAGES/myapp.mo
    dst: /usr/share/locale/sv/LC_MESSAGES/myapp.mo
    lang: sv   # generates %lang(sv) in RPM spec

This follows the existing pattern of type: doc which is also RPM-specific and ignored by
other packagers.

### Describe alternatives you've considered

..

### Search

- [x] I did search for other open and closed issues before opening this.

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

### Additional context


- https://rpm-packaging-guide.github.io/
- https://docs.fedoraproject.org/en-US/packaging-guidelines/

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions