定制 dnadesign/silverstripe-audio-definition 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dnadesign/silverstripe-audio-definition

Composer 安装命令:

composer require dnadesign/silverstripe-audio-definition

包简介

Provides the models and interface to include keywords audio definition in content

README 文档

README

Introduction

This modules provides an interface to associate foreign words, within a content area, with an audio description and optional text definition. By Default, this module ships with the necessary interfaces for translating Te Reo Maori words and expressions via the https://maoridictionary.co.nz API.

Requirements

  • SilverStripe 5
  • maoridictionary.co.nz API key (if using the default Te Reo Maori API)

Installation

composer require dnadesign/silverstripe-audio-definition

How to

Create Definitions

In the CMS, open the Audio Definition interface, and click on Add New. Type in the terms (could be one or more words) and select the language they are in (by default, only option is Maori).

If you are using an API and it is set up correctly, the Link to Audio file and Text Definitions should be populated upon saving. If no API is provided, you can add Text Definitions manually.

Insert definitions in a content area

This module adds a button to the default Silverstripe text editor (currently TinyMCE 6) allowing a user to insert a shortcode which renders the audio definition. To add the shortcode, select the word you wish to associate with the definition, click on the audio defnintion button and select the correct term. If the selected text matches any of the audio definition term, it will be selected by default.

Customise definition appearance

By default, the rendered definition is a span with the correct lang attribute set. In addition, if an audio file is supplied, a button will precede the word which will play the audio when clicked.

It is recommended that you override the DNADesign\AudioDefinition\AudioDefinition template to suit you needs. For instance, you could add the text definition in a tooltip displayed when a user hovers over the word.

As an example, this is the markup you could use with tippy.js

<%-- Keep outer span for accessibility, aria-expanded will be added to it by tippy --%>
<% if $DefinitionsToDisplay %>
<span class="audiodef-wrapper">
    <span tabindex="0" role="button" class="audio-definition-button" lang="$LangAttr" data-tooltip-trigger aria-expanded="false">$Content.RAW</span>
    <span class="tooltip-template audiodef-tooltip" style="display: none;" data-tippy-theme="wreda-theme--light">
        <button class="tooltip-close button-close" data-tooltip-close aria-label="close">$SVG('cross')</button>
        <span class="audiodef-tooltip__title">
            <% if $LinkToAudioFile %><button class="audiodef-trigger button-speaker" aria-controls="audiodef-player-{$ID}" type="button" aria-label="pronounce">$SVG('speaker')</button><% end_if %>
            <dfn>$Term</dfn>
        </span>
        <% if $DefinitionsToDisplay %>
            <% loop $DefinitionsToDisplay %>
                <span class="audiodef-tooltip__definition">
                    <span class="audiodef-tooltip__definition-content">$Content.RAW</span>
                    <span class="audiodef-tooltip__definition-type">$Top.LanguageName | $Type</span>
                </span>
            <% end_loop %>
        <% end_if %>
    </span>
<span>
<%-- Keep audio player outside the tippy template as it gets duplicated --%>
<% if $LinkToAudioFile %>
    <audio id="audiodef-player-{$ID}" crossorigin="anonymous">
        <source src="$LinkToAudioFile" type="audio/mpeg">
    </audio>
<% end_if %>
<% else %>
    $Content.RAW
<% end_if %>

Add different languages/translators

If you would like to add a different language to choose from when creating a definition, you can add a new locale to the AudioDefinition sources via the config:

DNADesign\AudioDefinition\Models\AudioDefinition:
  sources:
    es_ES: 'SpanishTranslationServiceClass'

A translation service is optional. If you choose to use one, you can create a new service which must implement DNADesign\AudioDefinition\Services. This class must define a method getDefinitionAndAudio which returns an array that must contain:

$data = [
    'audioSrc' => 'Link to audio file',
    'definitions' => [
        [
            'id' => 'Unique id of the definition (optional),
            'type' => 'Eg: noun, verb (optional),
            'content' => 'The text definition'
        ]
    ]
]

Extensions

Context Extension

Some languages can have multiple text definitions for the same word depending on the context. To tag different text definitions with keywords that depict a context, activate the context extension for the locale as follows:

DNADesign\AudioDefinition\Models\TextDefinition:
  use_context_for_locales:
    - mi_NZ

Once activated, users can create contexts in the Audio Definition > Contexts tab, then tag text definitions with one or more contexts. This won't have an influence on the way the definitions are displayed out-of-the-box, but if you implement a way of displaying the text definitions, then these can be filtered by context.

Note: if at least one text definition is tagged with a context, the wysiwyg dropdown will give the choice of word with a context. If a word is required to display all definitions, then each definition will need to be tagged with the "default" context.

Note: if you add the context config before running dev/build after installing the module, you will need to run dev/build twice for all the tables to be created.

NOTES

Icons made by Pixel perfect from www.flaticon.com

dnadesign/silverstripe-audio-definition 适用场景与选型建议

dnadesign/silverstripe-audio-definition 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 738 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 09 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「translation」 「audio」 「silverstripe」 「definition」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 dnadesign/silverstripe-audio-definition 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dnadesign/silverstripe-audio-definition 我们能提供哪些服务?
定制开发 / 二次开发

基于 dnadesign/silverstripe-audio-definition 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 738
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 6
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2021-09-15