snow-editor

small markdown and org-mode editor
Log | Files | Refs | README

strings.js (3528B)


      1 export const STR = {
      2   UNTITLED_DOCUMENT: 'Untitled document',
      3 
      4   SHARE: 'Share',
      5   SHARE_DOCUMENT: 'Share document',
      6   TITLE: 'Title',
      7   LINK_VALIDITY: 'Link validity',
      8   EXPIRY_1H: '1 hour',
      9   EXPIRY_24H: '24 hours',
     10   EXPIRY_7D: '7 days',
     11   EXPIRY_30D: '30 days',
     12   EXPIRY_NEVER: 'Never expires',
     13   EXPIRES_ON: (date) => `Expires on ${date}`,
     14   EXPIRES_SOON: 'Expires soon',
     15   CANCEL: 'Cancel',
     16   CLOSE: 'Close',
     17   CREATING: 'Creating…',
     18   CREATE_LINKS: 'Create links',
     19   VIEW_LINK: 'View link',
     20   EDIT_LINK: 'Edit link',
     21   COPY: 'Copy',
     22   COPIED: 'Copied',
     23   COPY_FAILED: 'Could not copy the link.',
     24 
     25   BADGE_ONLINE: 'Online',
     26   BADGE_SHARED: 'Shared',
     27   BADGE_READONLY: 'Read-only',
     28   BADGE_EDITING: 'Editing',
     29 
     30   SHARED_VIEW: 'Shared view',
     31   SHARED_EDIT: 'Shared edit',
     32   SAVE_TO_SERVER: 'Save to server',
     33   RELEASE_EDIT_LOCK: 'Release edit lock',
     34   DOWNLOAD_MD: 'Download .md',
     35   DOWNLOAD_ORG: 'Download .org',
     36 
     37   LOADING_DOCUMENT: 'Loading document…',
     38   OPEN_IN_SNOW_EDITOR: 'Open in Snow Editor',
     39 
     40   LINK_EXPIRED_TITLE: 'Link expired',
     41   LINK_EXPIRED_VIEW: 'This link has expired.',
     42   LINK_EXPIRED_EDIT: 'This edit link has expired.',
     43   DOCUMENT_NOT_FOUND_TITLE: 'Document not found',
     44   LOAD_ERROR_TITLE: 'Failed to load',
     45 
     46   LOCKED_BY_OTHER:
     47     'This document is being edited by someone else. You can view it, but not edit it right now.',
     48   LOCK_LOST:
     49     'You lost edit permission for this document. Your text was not deleted. Save a local copy before leaving.',
     50   LOCK_EXPIRES_AT: 'Lock expires at',
     51 
     52   SAVE_SAVING: 'Saving…',
     53   SAVE_SAVED: 'Saved',
     54   SAVE_ERROR: 'Save failed',
     55   SAVE_NO_PERMISSION: 'No edit permission',
     56 
     57   FOOTER_SHARED: 'Snow Editor · shared document',
     58 
     59   NOT_FOUND: 'Document not found.',
     60   EXPIRED: 'This link has expired.',
     61   DOCUMENT_LOCKED: 'This document is being edited by someone else.',
     62   LOCK_REQUIRED: 'You need an active edit lock to save.',
     63   CONTENT_TOO_LARGE: 'Document is larger than 1 MB.',
     64   RATE_LIMIT: 'Too many requests. Try again in a minute.',
     65   ORIGIN_NOT_ALLOWED:
     66     'Sharing is only available from the Snow Editor website. Open snow.pablomurad.com and try again.',
     67   NETWORK: 'Could not connect to the server. Check your connection.',
     68   GENERIC_ERROR: 'Something went wrong.',
     69   UNEXPECTED_ERROR: 'An unexpected error occurred.',
     70 
     71   VERSION_HISTORY: 'Version history',
     72   VERSION_LOADING: 'Loading versions…',
     73   VERSION_EMPTY: 'No saved versions yet.',
     74   VERSION_RESTORE: 'Restore',
     75   VERSION_RESTORING: 'Restoring…',
     76   VERSION_RESTORE_CONFIRM:
     77     'Restore this version? Your current content will be saved as a new version first.',
     78 
     79   ORG_OUTLINE: 'Outline',
     80 };
     81 
     82 export const EXPIRY_OPTIONS = [
     83   { value: '1h', label: STR.EXPIRY_1H },
     84   { value: '24h', label: STR.EXPIRY_24H },
     85   { value: '7d', label: STR.EXPIRY_7D },
     86   { value: '30d', label: STR.EXPIRY_30D },
     87   { value: 'never', label: STR.EXPIRY_NEVER },
     88 ];
     89 
     90 const DATE_LOCALE = 'en-US';
     91 const DATE_OPTIONS = { dateStyle: 'medium', timeStyle: 'short' };
     92 
     93 export function formatExpiryDate(iso) {
     94   if (!iso) return STR.EXPIRY_NEVER;
     95   try {
     96     return STR.EXPIRES_ON(new Date(iso).toLocaleString(DATE_LOCALE, DATE_OPTIONS));
     97   } catch {
     98     return STR.EXPIRES_SOON;
     99   }
    100 }
    101 
    102 export function formatLockExpiry(iso) {
    103   if (!iso) return null;
    104   try {
    105     return new Date(iso).toLocaleString(DATE_LOCALE, DATE_OPTIONS);
    106   } catch {
    107     return null;
    108   }
    109 }
    110 
    111 export function formatVersionDate(iso) {
    112   try {
    113     return new Date(iso).toLocaleString(DATE_LOCALE, DATE_OPTIONS);
    114   } catch {
    115     return iso;
    116   }
    117 }