Skip to content

Feature Request: Support for Accessing Translations via Key in intl_utils #129

Open
@TheWalkingDead2

Description

@TheWalkingDead2

Currently, the intl_utils package generates methods for each translation key from .arb files, which is convenient for static access. However, for some dynamic use cases where the translation keys are determined at runtime (e.g., fetched from a server or user-generated content), it would be beneficial to have the ability to access translations directly by key strings.

Proposed Feature
I propose adding functionality to the intl_utils package that allows developers to retrieve translations directly by specifying a key as a string. This would complement the existing method generation and not replace any current functionality.

Use Cases
Dynamic Content: Applications that receive part of their UI text from a server response which includes translation keys.
Plugin Systems: Allowing plugins or modules to specify their own keys without needing to regenerate the entire S class.
Suggested Implementation
A possible implementation could involve generating an additional method in the S class that takes a key as a string and returns the corresponding translation if it exists. Example:

String translate(String key) {
  switch(key) {
    case 'hello': return hello;
    case 'welcome': return welcome;
    // include all keys
    default: return key; // or throw, based on configuration
  }
}

Benefits
Flexibility: Allows developers to handle translations dynamically, increasing the flexibility of the intl_utils.
Integration: Makes it easier to integrate with dynamic content systems or external modules.
I believe this feature would significantly enhance the utility of intl_utils for many Flutter developers. Looking forward to your thoughts and feedback on this suggestion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions