insertHTMLFragments.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. This script will aid the process of inserting HTML fragments into all the
  3. locales.
  4. We are migrating from
  5. locale: 'PRE __key1__ POST'
  6. pug: translate(localeKey, { key1: '<b>VALUE</b>' })
  7. to
  8. locale: 'PRE <0>__key1__</0> POST'
  9. pug: translate(localeKey, { key1: 'VALUE' }, ['b'])
  10. MAPPING entries:
  11. localeKey: ['key1', 'key2']
  12. click_here_to_view_sl_in_lng: ['lngName']
  13. */
  14. import TransformLocales from './transformLocales.js'
  15. import { fileURLToPath } from 'url'
  16. const MAPPING = {
  17. support_lots_of_features: ['help_guides_link'],
  18. nothing_to_install_ready_to_go: ['start_now'],
  19. all_packages_and_templates: ['templatesLink'],
  20. github_merge_failed: ['sharelatex_branch', 'master_branch'],
  21. kb_suggestions_enquiry: ['kbLink'],
  22. sure_you_want_to_restore_before: ['filename'],
  23. you_have_added_x_of_group_size_y: ['addedUsersSize', 'groupSize'],
  24. x_price_per_month: ['price'],
  25. x_price_per_year: ['price'],
  26. x_price_for_first_month: ['price'],
  27. x_price_for_first_year: ['price'],
  28. sure_you_want_to_change_plan: ['planName'],
  29. subscription_canceled_and_terminate_on_x: ['terminateDate'],
  30. next_payment_of_x_collectected_on_y: ['paymentAmmount', 'collectionDate'],
  31. currently_subscribed_to_plan: ['planName'],
  32. recurly_email_update_needed: ['recurlyEmail', 'userEmail'],
  33. change_to_annual_billing_and_save: ['percentage', 'yearlySaving'],
  34. project_ownership_transfer_confirmation_1: ['user', 'project'],
  35. you_introed_high_number: ['numberOfPeople'],
  36. you_introed_small_number: ['numberOfPeople'],
  37. click_here_to_view_sl_in_lng: ['lngName'],
  38. }
  39. function transformLocale(locale, components) {
  40. components.forEach((key, idx) => {
  41. const i18nKey = `__${key}__`
  42. const replacement = `<${idx}>${i18nKey}</${idx}>`
  43. if (!locale.includes(replacement)) {
  44. locale = locale.replace(new RegExp(i18nKey, 'g'), replacement)
  45. }
  46. })
  47. return locale
  48. }
  49. function main() {
  50. TransformLocales.transformLocales(MAPPING, transformLocale)
  51. }
  52. if (
  53. fileURLToPath(import.meta.url).replace(/\.js$/, '') ===
  54. process.argv[1].replace(/\.js$/, '')
  55. ) {
  56. main()
  57. }