From 4f9f4a97adfd77598c0b47b0fad27ac8950bf424 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Fri, 5 Jul 2019 14:51:36 -0600 Subject: [PATCH] Set up orthography translation Also fix dictionary description not auto-linking --- src/constants.js | 2 +- src/js/dictionaryManagement.js | 10 +++------- src/js/migration.js | 2 +- src/js/render.js | 8 +++++--- src/js/wordManagement.js | 12 +++++++++++- src/php/api/Dictionary.php | 9 +++++++-- template-index.html | 7 +++++++ 7 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/constants.js b/src/constants.js index d30aae9..dca587e 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,6 +1,6 @@ import { getTimestampInSeconds } from "./helpers"; -export const MIGRATE_VERSION = '2.1.0'; +export const MIGRATE_VERSION = '2.0.1'; export const DEFAULT_DICTIONARY = { name: 'New', specification: 'Dictionary', diff --git a/src/js/dictionaryManagement.js b/src/js/dictionaryManagement.js index 3c609e1..c464d7e 100644 --- a/src/js/dictionaryManagement.js +++ b/src/js/dictionaryManagement.js @@ -30,6 +30,7 @@ export function openEditModal() { document.getElementById('editCoda').value = phonotactics.coda.join(','); document.getElementById('editPhonotacticsNotes').value = phonotactics.notes; + document.getElementById('editTranslations').value = orthography.translations.join('\n'); document.getElementById('editOrthography').value = orthography.notes; document.getElementById('editGrammar').value = grammar.notes; @@ -59,18 +60,16 @@ export function saveEditModal() { window.currentDictionary.details.phonotactics.coda = document.getElementById('editCoda').value.split(',').map(val => val.trim()).filter(val => val !== ''); window.currentDictionary.details.phonotactics.notes = removeTags(document.getElementById('editPhonotacticsNotes').value.trim()); + window.currentDictionary.details.orthography.translations = document.getElementById('editTranslations').value.split('\n').map(val => val.trim()).filter(val => val !== ''); window.currentDictionary.details.orthography.notes = removeTags(document.getElementById('editOrthography').value.trim()); window.currentDictionary.details.grammar.notes = removeTags(document.getElementById('editGrammar').value.trim()); window.currentDictionary.settings.allowDuplicates = !document.getElementById('editPreventDuplicates').checked; window.currentDictionary.settings.caseSensitive = document.getElementById('editCaseSensitive').checked; - const needsReSort = window.currentDictionary.settings.sortByDefinition !== document.getElementById('editSortByDefinition').checked; window.currentDictionary.settings.sortByDefinition = document.getElementById('editSortByDefinition').checked; window.currentDictionary.settings.theme = document.getElementById('editTheme').value; - let needsWordRender = false; if (hasToken()) { - needsWordRender = window.currentDictionary.settings.isPublic !== document.getElementById('editIsPublic').checked; window.currentDictionary.settings.isPublic = document.getElementById('editIsPublic').checked; } else { window.currentDictionary.settings.isPublic = false; @@ -81,10 +80,7 @@ export function saveEditModal() { renderTheme(); renderDictionaryDetails(); renderPartsOfSpeech(); - - if (needsReSort || needsWordRender) { - sortWords(true); - } + sortWords(true); if (hasToken()) { import('./account/index.js').then(account => { diff --git a/src/js/migration.js b/src/js/migration.js index f716ef6..5976bf6 100644 --- a/src/js/migration.js +++ b/src/js/migration.js @@ -110,7 +110,7 @@ export function migrateDictionary() { delete window.currentDictionary.details.phonology.phonotactics; window.currentDictionary.details.phonotactics.notes = window.currentDictionary.details.phonotactics.exceptions; delete window.currentDictionary.details.phonotactics.exceptions; - // Add window.currentDictionary.details.orthography.translations = []; + window.currentDictionary.details.orthography.translations = []; // Add window.currentDictionary.custom.css = ''; window.currentDictionary = Object.assign({}, DEFAULT_DICTIONARY, window.currentDictionary); window.currentDictionary.version = MIGRATE_VERSION; diff --git a/src/js/render.js b/src/js/render.js index dcc025f..8764a48 100644 --- a/src/js/render.js +++ b/src/js/render.js @@ -15,7 +15,7 @@ import { setupIPAFields } from './setupListeners'; import { getPaginationData } from './pagination'; -import { getOpenEditForms, parseReferences } from './wordManagement'; +import { getOpenEditForms, translateOrthography, parseReferences } from './wordManagement'; import { renderAd } from './ads'; import ipaTableFile from './KeyboardFire/phondue/ipa-table.html'; import { getPublicLink } from './account/utilities'; @@ -68,7 +68,7 @@ export function renderName() { } export function renderDescription() { - const descriptionHTML = md(removeTags(window.currentDictionary.description)); + const descriptionHTML = md(parseReferences(removeTags(window.currentDictionary.description))); document.getElementById('detailsPanel').innerHTML = '
' + descriptionHTML + '
'; } @@ -199,9 +199,11 @@ export function renderWords() { wordsHTML += renderAd(displayIndex); + let wordNameDisplay = translateOrthography(word.name); + wordsHTML += `
-

${word.name}${homonymnNumber > 0 ? ' ' + homonymnNumber.toString() + '' : ''}

+

${wordNameDisplay}${homonymnNumber > 0 ? ' ' + homonymnNumber.toString() + '' : ''}

${word.pronunciation} ${word.partOfSpeech} ${isPublic ? `` : ''} diff --git a/src/js/wordManagement.js b/src/js/wordManagement.js index 0a62d6d..a192346 100644 --- a/src/js/wordManagement.js +++ b/src/js/wordManagement.js @@ -46,6 +46,16 @@ export function sortWords(render) { } } +export function translateOrthography(word) { + window.currentDictionary.details.orthography.translations.forEach(translation => { + translation = translation.split('=').map(value => value.trim()); + if (translation.length > 1 && translation[0] !== '' && translation[1] !== '') { + word = word.replace(new RegExp(translation[0], 'g'), translation[1]); + } + }); + return word; +} + export function parseReferences(detailsMarkdown) { const references = detailsMarkdown.match(/\{\{.+?\}\}/g); if (references && Array.isArray(references)) { @@ -81,7 +91,7 @@ export function parseReferences(detailsMarkdown) { homonymn = 1; } const homonymnSubHTML = homonymn > 0 ? '' + homonymn.toString() + '' : ''; - const wordMarkdownLink = `[${wordToFind}${homonymnSubHTML}](#${existingWordId})`; + const wordMarkdownLink = `[${translateOrthography(wordToFind)}${homonymnSubHTML}](#${existingWordId})`; detailsMarkdown = detailsMarkdown.replace(new RegExp(reference, 'g'), wordMarkdownLink); } }); diff --git a/src/php/api/Dictionary.php b/src/php/api/Dictionary.php index e701676..0e9c224 100644 --- a/src/php/api/Dictionary.php +++ b/src/php/api/Dictionary.php @@ -33,13 +33,14 @@ class Dictionary { $insert_dictionary = $this->db->execute($insert_dictionary_query, array($new_id, $user, 'A new dictionary.', time())); if ($insert_dictionary === true) { - $insert_linguistics_query = "INSERT INTO dictionary_linguistics (dictionary, parts_of_speech, phonotactics_notes, orthography_notes, grammar_notes) -VALUES ($new_id, ?, ?, ?, ?)"; + $insert_linguistics_query = "INSERT INTO dictionary_linguistics (dictionary, parts_of_speech, phonotactics_notes, translations, orthography_notes, grammar_notes) +VALUES ($new_id, ?, ?, ?, ?, ?)"; $insert_linguistics = $this->db->execute($insert_linguistics_query, array( $this->defaults['partsOfSpeech'], '', '', '', + '', )); if ($insert_linguistics === true) { @@ -117,6 +118,7 @@ VALUES ($new_id, ?, ?, ?, ?)"; 'notes' => $result['phonotactics_notes'], ), 'orthography' => array( + 'translations' => $result['translations'] !== '' ? explode(PHP_EOL, $result['translations']) : array(), 'notes' => $result['orthography_notes'], ), 'grammar' => array( @@ -268,6 +270,7 @@ VALUES ($new_id, ?, ?, ?, ?)"; 'notes' => $result['phonotactics_notes'], ), 'orthography' => array( + 'translations' => $result['translations'] !== '' ? explode(PHP_EOL, $result['translations']) : array(), 'notes' => $result['orthography_notes'], ), 'grammar' => array( @@ -327,6 +330,7 @@ SET parts_of_speech=:parts_of_speech, nucleus=:nucleus, coda=:coda, phonotactics_notes=:phonotactics_notes, + translations=:translations, orthography_notes=:orthography_notes, grammar_notes=:grammar_notes WHERE dictionary=$dictionary"; @@ -341,6 +345,7 @@ WHERE dictionary=$dictionary"; ':nucleus' => implode(',', $linguistics['phonotactics']['nucleus']), ':coda' => implode(',', $linguistics['phonotactics']['coda']), ':phonotactics_notes' => $linguistics['phonotactics']['notes'], + ':translations' => implode(PHP_EOL, $linguistics['orthography']['translations']), ':orthography_notes' => $linguistics['orthography']['notes'], ':grammar_notes' => $linguistics['grammar']['notes'], )); diff --git a/template-index.html b/template-index.html index 4272244..8ac892d 100644 --- a/template-index.html +++ b/template-index.html @@ -310,6 +310,13 @@

Orthography

+