Skip to main content

LocalizationUtils

Import :

const LocalizationUtils = brackets.getModule("utils/LocalizationUtils")

getLocalizedLabel(locale) ⇒ string

Converts a language code to its written name, if possible. If not possible, the language code is simply returned.

Kind: global function
Returns: string - The language's name or the given language code

ParamTypeDescription
localestringThe two-char language code

getFormattedDateTime([date], [lang], [dateTimeFormat]) ⇒ string

Formats a given date object into a locale-aware date and time string.

Kind: global function
Returns: string - - The formatted date and time string (e.g., "Dec 24, 2024, 10:30 AM").

ParamTypeDescription
[date]DateThe date object to format. If not provided, the current date and time will be used.
[lang]stringOptional language code to use for formatting (e.g., 'en', 'fr'). If not provided, defaults to the application locale or 'en'.
[dateTimeFormat]ObjectOptional object specifying the date and time formatting options. Defaults to { dateStyle: 'medium', timeStyle: 'short' }.
[dateTimeFormat.dateStyle]stringSpecifies the date format style. One of: DATE_TIME_STYLE.*
[dateTimeFormat.timeStyle]stringSpecifies the time format style. One of: DATE_TIME_STYLE.*

dateTimeFromNow([date], [lang], [fromDate]) ⇒ string

Returns a relative time string (e.g., "2 days ago", "in 3 hours") based on the difference between the given date and now.

Kind: global function
Returns: string - - A human-readable relative time string (e.g., "2 days ago", "in 3 hours").

ParamTypeDescription
[date]DateThe date to compare with the current date and time. If not given, defaults to now.
[lang]stringOptional language code to use for formatting (e.g., 'en', 'fr'). If not provided, defaults to the application locale or 'en'.
[fromDate]DateOptional date to use instead of now to compute the relative dateTime from.

dateTimeFromNowFriendly(date, [lang], [fromDate]) ⇒ string

Returns an intelligent date string.

  • For dates within the last 30 days or the future: relative time (e.g., "2 days ago", "in 3 hours").
  • For dates earlier this year: formatted date (e.g., "Jan 5").
  • For dates not in the current year: formatted date with year (e.g., "Jan 5, 2023").

Kind: global function
Returns: string - - An intelligently formatted date string.

ParamTypeDescription
dateDateThe date to compare and format.
[lang]stringOptional language code to use for formatting (e.g., 'en', 'fr').
[fromDate]DateOptional date to use instead of now to compute the relative dateTime from.