Skip to content

Conversation

@marcojakob
Copy link

Overview

This PR implements comprehensive language support across all feed formats (Atom 1.0, JSON Feed 1.1, and RSS 2.0), addressing issue #196 which requested language support in Atom feeds. The implementation goes beyond the original request to provide consistent language functionality across all supported feed formats.

What's New

Atom 1.0 Language Support

  • Feed-level language: Added xml:lang attribute to <feed> element when language is specified
  • Per-item language: Individual <entry> elements can have their own xml:lang attributes
  • Security: Language values are properly sanitized to prevent XML injection attacks
  • Standards compliance: Follows Atom 1.0 specification for language declarations

JSON Feed 1.1 Enhancement

  • Upgraded to JSON Feed 1.1: Updated from version 1.0 to support the language field
  • Feed-level language: Added language field to top-level feed object
  • Per-item language: Individual items can specify their own language
  • Backward compatibility: Maintains compatibility while adding new features

RSS 2.0 Verification

  • Confirmed existing support: RSS 2.0 already had channel-level <language> element support
  • Added test coverage: Comprehensive tests for RSS language functionality
  • Documented limitations: RSS 2.0 spec doesn't support per-item language (by design)

Technical Implementation

Type System Updates

  • Added language?: string to the Item interface for per-item language support
  • Existing FeedOptions.language field was already present and working

Security Enhancements

  • Language attributes are sanitized using the existing sanitize() function
  • Prevents XML/XSS injection attacks via malformed language codes

Standards Compliance

  • Atom: Uses xml:lang attributes as per W3C Atom specification
  • JSON Feed: Follows JSON Feed 1.1 specification for language support
  • RSS: Respects RSS 2.0 limitations (channel-level only)

Testing

Created dedicated test files for maintainability:

  • atom1.language.test.ts
  • json.language.test.ts
  • rss2.language.test.ts

Test Coverage Includes:

  • Feed-level and item-level language support
  • Multiple language codes (en, fr, es-ES, zh-CN, ja-JP, pt-BR, etc.)
  • Security testing with malicious input
  • Edge cases and validation
  • Format-specific behavior verification

Language Support Matrix

Format Feed-Level Item-Level Implementation Status
Atom 1.0 xml:lang xml:lang Complete
JSON Feed 1.1 language language Complete
RSS 2.0 <language> ❌ Spec limitation Complete

Usage Examples

Basic Feed-Level Language

const feed = new Feed({
  title: "My Blog",
  language: "en-US", // Now supported across all formats
  // ... other options
});

Per-Item Language Support

feed.addItem({
  title: "Article en Français",
  language: "fr-FR", // Atom & JSON Feed only
  // ... other item properties
});

Related Issues

Copy link

@Greenheart Greenheart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing this! I was just about to do this myself, but was happily surprised it was already done 😄

Tests look good, pass, and the code looks good.

Some comments about related tasks, but some of them might be better suited for separate issues and PRs.

Copy link

@Greenheart Greenheart Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The language support for JSON feeds looks good. Thanks for implementing this!

feedItem.language = item.language;
}

if (item.author) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this PR is about improving support for language, and not primarily about supporting JSON Feed v1.1.

However, JSON Feed v1.1 deprecated the top-level author in favour of the top-level authors array. It's still safe to use the author field, and technically this the output is still valid JSON Feed v1.1. However, this library doesn't yet support all of the features of the JSON Feed 1.1 specification, like the authors field which seem to be the future-proofed method.

Adding support for authors might be better to solve in a follow-up issue and separate PR.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comments:

  1. Since this changes the behaviour of language, it would be good to also update the README to indicate that language is now supported for all feed formats.

  2. Ideally, also update the README to note that it's now possible to specify language on individual feed items.

Making these changes as part of this PR would be ideal to avoid confusion for new users, but these changes could also be a follow-up PR to get this merged more quickly.

if (ins.options.language) {
// Atom uses the reserved "xml:" namespace for language;
// no extra xmlns declaration is required.
feedAttrs["xml:lang"] = sanitize(ins.options.language) || ins.options.language;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why fall back to the unsanitized value if the sanitization fails or returns a falsy value? Wouldn't it be better to throw an error, or log a warning and omit the language field instead?

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.

language should be supported in atom feeds

2 participants