Set up orthography translation

Also fix dictionary description not auto-linking
This commit is contained in:
Robbie Antenesse 2019-07-05 14:51:36 -06:00 committed by Robbie Antenesse
parent 1c2570684d
commit 4f9f4a97ad
7 changed files with 35 additions and 15 deletions

View File

@ -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',

View File

@ -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 => {

View File

@ -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;

View File

@ -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 = '<div class="content">' + descriptionHTML + '</div>';
}
@ -199,9 +199,11 @@ export function renderWords() {
wordsHTML += renderAd(displayIndex);
let wordNameDisplay = translateOrthography(word.name);
wordsHTML += `<article class="entry" id="${word.wordId}">
<header>
<h4 class="word">${word.name}${homonymnNumber > 0 ? ' <sub>' + homonymnNumber.toString() + '</sub>' : ''}</h4>
<h4 class="word">${wordNameDisplay}${homonymnNumber > 0 ? ' <sub>' + homonymnNumber.toString() + '</sub>' : ''}</h4>
<span class="pronunciation">${word.pronunciation}</span>
<span class="part-of-speech">${word.partOfSpeech}</span>
${isPublic ? `<a class="small button share-link" href="${shareLink}" target="_blank" title="Public Link to Word">&#10150;</a>` : ''}

View File

@ -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 ? '<sub>' + homonymn.toString() + '</sub>' : '';
const wordMarkdownLink = `[${wordToFind}${homonymnSubHTML}](#${existingWordId})`;
const wordMarkdownLink = `[${translateOrthography(wordToFind)}${homonymnSubHTML}](#${existingWordId})`;
detailsMarkdown = detailsMarkdown.replace(new RegExp(reference, 'g'), wordMarkdownLink);
}
});

View File

@ -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'],
));

View File

@ -310,6 +310,13 @@
<textarea id="editPhonotacticsNotes"></textarea>
</label>
<h3>Orthography</h3>
<label>Translations <small>(One translation per line)</small><a class="label-button maximize-button">Maximize</a><br>
<textarea id="editTranslations" placeholder="ai=I
AA=ay
ou=ow"></textarea>
<small>Use format: <code>sequence=replacement</code></small><br>
<small>Translations occur in the order specified here, so try to avoid double translations!</small>
</label>
<label>Notes <small>(Markdown-enabled)</small><a class="label-button maximize-button">Maximize</a><br>
<textarea id="editOrthography"></textarea>
</label>