freedesktop_desktop_entry 0.2.0 copy "freedesktop_desktop_entry: ^0.2.0" to clipboard
freedesktop_desktop_entry: ^0.2.0 copied to clipboard

outdated

A Dart package for parsing freedesktop desktop entries on Linux.

A Dart package for parsing freedesktop desktop entries on Linux.

Features #

  • Obtain values by key
  • Obtain localized values by locale
  • Localize values according to the locale matching rules of the specification.
  • Localize entire desktop entries for easier access.

This package provides the DesktopEntryKey enum for convenience, but it doesn't make any assumptions about value types and whether a key is required or not. All keys are considered optional.

Usage #

import 'package:freedesktop_desktop_entry/freedesktop_desktop_entry.dart';
import 'dart:io';

final file = File("desktop-entry.desktop");
String content = file.readAsStringSync();

DesktopEntry desktopEntry = DesktopEntry.parse(content);

// Localize an entire desktop entry according to official locale matching rules.
// Probably what you want.
LocalizedDesktopEntry localizedDesktopEntry = desktopEntry.localize(lang: 'fr', country: 'BE');
String? localizedComment = localizedDesktopEntry.entries[DesktopEntryKey.comment.string];
print(localizedComment);

// Get default value of entry.
bool? terminal = desktopEntry.entries[DesktopEntryKey.terminal.string]?.value.getBoolean();
print(terminal);

// Get a single localized value by exact locale.
String? frenchComment =
desktopEntry.entries[DesktopEntryKey.comment.string]
    ?.localizedValues[Locale(lang: 'fr', country: 'BE')];
print(frenchComment);

// Localize a single value according to official locale matching rules.
List<String>? frenchOrDefaultKeywords = desktopEntry.entries[DesktopEntryKey.keywords.string]
    ?.localize(lang: 'fr', country: 'BE')
    .getStringList();
print(frenchOrDefaultKeywords);
3
likes
0
points
130
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart package for parsing freedesktop desktop entries on Linux.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

freezed_annotation

More

Packages that depend on freedesktop_desktop_entry