all repos — snow-editor @ main

small and cozy markdown, and orgmode editor

src/lib/strings.js (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
export const STR = {
  UNTITLED_DOCUMENT: 'Untitled document',

  SHARE: 'Share',
  SHARE_DOCUMENT: 'Share document',
  TITLE: 'Title',
  LINK_VALIDITY: 'Link validity',
  EXPIRY_1H: '1 hour',
  EXPIRY_24H: '24 hours',
  EXPIRY_7D: '7 days',
  EXPIRY_30D: '30 days',
  EXPIRY_NEVER: 'Never expires',
  EXPIRES_ON: (date) => `Expires on ${date}`,
  EXPIRES_SOON: 'Expires soon',
  CANCEL: 'Cancel',
  CLOSE: 'Close',
  CREATING: 'Creating…',
  CREATE_LINKS: 'Create links',
  VIEW_LINK: 'View link',
  EDIT_LINK: 'Edit link',
  COPY: 'Copy',
  COPIED: 'Copied',
  COPY_FAILED: 'Could not copy the link.',

  BADGE_ONLINE: 'Online',
  BADGE_SHARED: 'Shared',
  BADGE_READONLY: 'Read-only',
  BADGE_EDITING: 'Editing',

  SHARED_VIEW: 'Shared view',
  SHARED_EDIT: 'Shared edit',
  SAVE_TO_SERVER: 'Save to server',
  RELEASE_EDIT_LOCK: 'Release edit lock',
  DOWNLOAD_MD: 'Download .md',
  DOWNLOAD_ORG: 'Download .org',

  LOADING_DOCUMENT: 'Loading document…',
  OPEN_IN_SNOW_EDITOR: 'Open in Snow Editor',

  LINK_EXPIRED_TITLE: 'Link expired',
  LINK_EXPIRED_VIEW: 'This link has expired.',
  LINK_EXPIRED_EDIT: 'This edit link has expired.',
  DOCUMENT_NOT_FOUND_TITLE: 'Document not found',
  LOAD_ERROR_TITLE: 'Failed to load',

  LOCKED_BY_OTHER:
    'This document is being edited by someone else. You can view it, but not edit it right now.',
  LOCK_LOST:
    'You lost edit permission for this document. Your text was not deleted. Save a local copy before leaving.',
  LOCK_EXPIRES_AT: 'Lock expires at',

  SAVE_SAVING: 'Saving…',
  SAVE_SAVED: 'Saved',
  SAVE_ERROR: 'Save failed',
  SAVE_NO_PERMISSION: 'No edit permission',

  FOOTER_SHARED: 'Snow Editor · shared document',

  NOT_FOUND: 'Document not found.',
  EXPIRED: 'This link has expired.',
  DOCUMENT_LOCKED: 'This document is being edited by someone else.',
  LOCK_REQUIRED: 'You need an active edit lock to save.',
  CONTENT_TOO_LARGE: 'Document is larger than 1 MB.',
  RATE_LIMIT: 'Too many requests. Try again in a minute.',
  ORIGIN_NOT_ALLOWED:
    'Sharing is only available from the Snow Editor website. Open snow.pablomurad.com and try again.',
  NETWORK: 'Could not connect to the server. Check your connection.',
  GENERIC_ERROR: 'Something went wrong.',
  UNEXPECTED_ERROR: 'An unexpected error occurred.',

  VERSION_HISTORY: 'Version history',
  VERSION_LOADING: 'Loading versions…',
  VERSION_EMPTY: 'No saved versions yet.',
  VERSION_RESTORE: 'Restore',
  VERSION_RESTORING: 'Restoring…',
  VERSION_RESTORE_CONFIRM:
    'Restore this version? Your current content will be saved as a new version first.',

  ORG_OUTLINE: 'Outline',

  TAB_WRITE: 'Write',
  TAB_READ: 'Read',
  PREVIEW_EMPTY: 'The preview appears here as you write…',
  PREVIEW_RENDERING: 'Preparing preview…',
  RESIZE_PANELS: 'Drag to resize panels. Double-click to reset.',

  DRAFTS: 'Drafts',
  NEW_DRAFT: 'New draft',
  DELETE_DRAFT: 'Delete draft',
  DELETE_DRAFT_CONFIRM: (title) =>
    `Delete "${title}"? This cannot be undone.`,
};

export const EXPIRY_OPTIONS = [
  { value: '1h', label: STR.EXPIRY_1H },
  { value: '24h', label: STR.EXPIRY_24H },
  { value: '7d', label: STR.EXPIRY_7D },
  { value: '30d', label: STR.EXPIRY_30D },
  { value: 'never', label: STR.EXPIRY_NEVER },
];

const DATE_LOCALE = 'en-US';
const DATE_OPTIONS = { dateStyle: 'medium', timeStyle: 'short' };

export function formatExpiryDate(iso) {
  if (!iso) return STR.EXPIRY_NEVER;
  try {
    return STR.EXPIRES_ON(new Date(iso).toLocaleString(DATE_LOCALE, DATE_OPTIONS));
  } catch {
    return STR.EXPIRES_SOON;
  }
}

export function formatLockExpiry(iso) {
  if (!iso) return null;
  try {
    return new Date(iso).toLocaleString(DATE_LOCALE, DATE_OPTIONS);
  } catch {
    return null;
  }
}

export function formatVersionDate(iso) {
  try {
    return new Date(iso).toLocaleString(DATE_LOCALE, DATE_OPTIONS);
  } catch {
    return iso;
  }
}